• I am wondering if there is a way to force the capitalization of the First & Last Name fields in my forms when a user submits. I don’t care if the user sees the change or not, I am more interested in the submission that gets processed being changed before the data from the form gets posted.

    So if

    joHn doE, jOHN DOE, or john doe are entered they would all be changed to John Doe (first letter capitalized, others lowercase).

    Here are my fields for reference:
    <label> First name
    [text* FirstName id:] </label>
    <label> Last name
    [text* LastName] </label>

    Thanks in advance if you can help with this!

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @mayday295,

    This code snippet do the trick:

    /**
     * Contact Form 7:
     * Uppercase the first letter the user name (e.g. John Doe)
     */
    add_filter( 'wpcf7_mail_tag_replaced', function( $replaced, $submitted, $html, $mail_tag ) {
    	// Replace 'your-name' with the actual name of the field you use to get the user name
    	if ( 'your-name' == $mail_tag->field_name() ) {
    		$replaced = strtolower( $submitted );
    		$replaced = ucwords( $replaced );
    	}
    	return $replaced;
    }, 10, 4 );

    See Customizing mail-tag replacement

    Thread Starter mayday295

    (@mayday295)

    Thanks Yordan!

    One other thing, is there something that can be added so when the name is passed as a variable via the URL, it can also be formatted the same way?

    As it is, the name gets corrected after submitting, but when I pass the user First name variable through the url as a parameter, it passes as typed originally. Given the way I use this variable on the following page, I would prefer it be passed directly formatted, as opposed to changing it after since it’s in-line with other text.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Forced Capitalization of First & Last Name Fields’ is closed to new replies.