• Resolved Ibby

    (@ibby)


    Hi

    We get lots of issues with users not filling in their email addresses properly on registration and we wanted to add an additional email address field and only allow the form to submit if the two email fields match (the form should show an error if they don’t).

    Is this possible?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @ibby

    I hope you’re well today!

    There’s no e-mail confirmation field out of the box but it is doable with a small bit of additional code:

    1. add second e-mail field to the form
    2. then add code as a Must-Use plugin to the site:

    – create an empty file with a .php extension (e.g. “forminator-confirm-email.php”)
    – copy and paste following code into it

    <?php 
    
    add_filter( 'forminator_custom_form_submit_errors', 'check_form_data', 99, 3 );
    function check_form_data( $submit_errors, $form_id, $field_data_array ) {
    	
    	if ( $form_id<> 123 )
    		return $submit_errors;
    
    	$email1 = $email2 = '';
    
    	foreach( $field_data_array as $arr ) {
    
    		if( $arr['name'] == 'email-1' ) $email1 = $arr['value'];
    		if( $arr['name'] == 'email-2' ) $email2 = $arr['value'];
    
    		if( '' != $email1 && '' != $email2 ) break;
    	}
    
    	if( $email1 != $email2 ) {
    		$submit_errors[]['email-2'] = 'The email addresses must match!';
    	}
    
    	return $submit_errors;
    }

    – in this line replace 123 with your form ID (it’s the number you see in form’s shortcode)

    if ( $form_id<> 123 )

    – in these lines replace email-1 and email-2 with your e-mail fields IDs if they are different

    if( $arr['name'] == 'email-1' ) $email1 = $arr['value'];
    if( $arr['name'] == 'email-2' ) $email2 = $arr['value'];

    – and in this one you can adjust error message (note, make sure that email-2 here is also replaced with and ID of second e-mail field if necessary)

    $submit_errors[]['email-2'] = 'The email addresses must match!';

    – finally, save the file and upload it to the “/wp-content/mu-plugins” folder of your site’s WordPress installation.

    It should work out of the box and if one of the fields is empty or it has different e-mail address than the other, it should issue the error and prevent form submission.

    Best regards,
    Adam

    Thread Starter Ibby

    (@ibby)

    Hi @wpmudev-support8

    Thank you very much, works like a charm!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Repeat email validation on signup form’ is closed to new replies.