• Resolved jokubas2000k

    (@jokubas2000k)


    Hi,

    I’m trying to achieve a system whereby the email address is entered twice and the two need to match to validate.

    The email address is extremely important for me as I use it to collect payments from customers so I can not afford to lose any customers because of a typo.

    I have found this topic: https://premium.wpmudev.org/forums/topic/forminator-pro-forminator-confirm-email-address/#post-1399734

    I tried using the following code:

    add_filter( 'forminator_custom_form_submit_errors', 'check_form_data', 99, 3 );
    
    function check_form_data( $submit_errors, $form_id, $field_data_array ) {
    
    $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;
    
    }

    I created 2 separate Email address fields (https://ibb.co/6mnxp5c) and added the above code to my child theme’s functions.php (I use a plugin called Code Snippets to edit the functions.php).

    But it did not work for me.

    Can someone please help me achieve this?

    Thanks in advance

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

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

    (@wpmudev-support7)

    Hello @jokubas2000k,

    I tried the same and it worked for me like a. charm. I am really sorry to know it did not work for you initially. Could you try to add it as a mu-plugin and then check if the same works for you?

    Here is the complete code for your reference

    <?php
      
      add_filter( 'forminator_custom_form_submit_errors', 'check_form_data', 99, 3 );
    
    function check_form_data( $submit_errors, $form_id, $field_data_array ) {
    
    $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;
    
    }

    Here are the step by step instructions with screenshots on how to make a mu-plugin:
    https://premium.wpmudev.org/docs/getting-started/download-wpmu-dev-plugins-themes/#installing-mu-plugins

    If that does not work, could you please export the form by navigating to Forminator-> Forms-> click the gear button beside the form name and hit the export button. You can add the form in the code block here or add the export file to google drive or dropbox or also use Pastebin. Remember to strip of all the confidential data such as emails from the email notifications section of the form. Do let me know if that works for you.

    Thank you,
    Prathamesh Palve

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @jokubas2000k

    I hope you are doing well.

    We haven’t heard from you in a while, I’ll go and mark this thread as resolved.

    However, feel free to let us know if you have any additional question or problem.

    Best Regards
    Patrick Freitas

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