• Resolved inspired888

    (@inspired888)


    Hi there,

    On the WPMUDEV forums I found this post, sharing this script for setting up a confirmation email field, and checking they match.

    It works well, except for the error message. The message it displays (at the top of the form) when the two email addresses don’t match is: “Error: Your form is not valid, please fix the errors!”

    Great form plug-in, by the way. So much slicker than most of those I’ve used before.

    Thanks very much,

    Jonathan

    That’s not what I’d like to display, as it’s not useful. Is there a way to change this?

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

    (@wpmudev-support8)

    Hi @inspired888

    I hope you’re well today and thank you for your question!

    The code “as is” adds error directly to the second e-mail field, keeping the “generic” error for the form itself. Here’s a slightly modified version that will display also add the error message on the top of the form:

    <?php
    
    add_filter('forminator_custom_form_submit_errors', 'my_custom_form_validation', 10, 3);
    
    function my_custom_form_validation($submit_errors, $form_id, $field_data_array) {
    
      // Skip if is not the correct form
      if( (int) $form_id !== 1483 ){
        return;
       }
    
        $fields = [];
        $fields[] = $_POST['email-1'];
        $fields[] = $_POST['email-2'];
    
          // Check if both emails are the same
          if (count(array_unique($fields)) !== 1) {
            // Custom error
            $submit_errors[][ 'email-2'] = __( 'Emails do not match' );
    		// custom error on top of form
    		add_filter( 'forminator_custom_form_invalid_form_message', 'my_custom_validation_custom_error', 10, 1 );
          }
    
      // Always return $submit_errors
      return $submit_errors;
    
    }
    
    function my_custom_validation_custom_error($error_message) {
    	
    	
    	$error_message .= ' ' . __( 'Emails do not match' );
    	return $error_message;
    	
    }

    Best regards,
    Adam

    Plugin Support Kasia – WPMU DEV Support

    (@wpmudev-support2)

    Hello @inspired888 ,

    We haven’t heard from you for a while now, so it looks like you don’t need our assistance anymore.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Email address confirmation script’ is closed to new replies.