[Forminator Pro] Forminator confirm email address

Hi

I have a development site here http://driftershire.co.uk?bypass=developmet-site

on the form my client would like the system whereby the email address is entered twice and the two need to match to validate, is there a way of achieving this, with this plugin?

Thank you

  • Adam Czajczyk
    • Support Gorilla

    Hello Neil

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

    Currently this is not possible “out of the box” but Forminator provides an API (see here) so I think it might be doable with some additional piece of code.

    However, I’ll need to consult that with our developers. I’ve already passed the question to them so please keep track of this ticket and we’ll update you here as soon as we get to know more from them.

    Best regards,

    Adam

  • Ash
    • Code Norris

    Hello Neil

    Please try 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;
    }

    You can use this code in your child theme's functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Here is a little thing you should notice. In the following two lines:

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

    email-1 and email-2 should come from your forminator settings. Please follow the screenshot to find the correct slugs:

    [attachments are only viewable by logged-in members]

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,

    Ash

  • Antonio
    • Site Builder, Child of Zeus

    It is not working for me.

    I see there is a :

    add_filter( ‘forminator_custom_form_submit_errors’, ‘check_form_data’, 99, 3 );

    that ‘check_form_data’, 99, 3 is an error ?

    my form intro code form is [forminator_form id=”52721″]

    I am using forminator, last version on 16 may 2019.

    Maybe something changed?

    • Adam Czajczyk
      • Support Gorilla

      Hi Antonio

      I hope you’re fine today!

      The “check_form_data’, 99, 3 is not an error.

      – the “check_form_data” string is a name of a callback function that’s hooked up to the “forminator_custom_form_submit_errors” filter and you can see that function in the code.

      – the 99 number is a priority value, the higher it is the later the hook is applied – it basically means that it’s applied after other callback functions were applied

      – the 3 number is a number of parameters the callback function takes, you can see in the code that there are three of them

      function check_form_data( $submit_errors, $form_id, $field_data_array ) {

      I’ve just tested this code on my own setup and it’s working fine so there are two probable reasons for it not working on your end:

      1) please make sure that in this lines

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

      in the code you have updated ’email-1′ and ’email-2′ strings after == to match your e-mail fields IDs in forminator. See screenshot please in this post above:

      https://wpmudev.com/forums/topic/forminator-pro-forminator-confirm-email-address#post-1374138

      2) there’s something interfering with the code or the code is added in a wrong place

      That said, please make sure about point 1 above and if that’s not it, please create a separate ticket of your own on our support forum (make sure to include a link to this one too there for reference) and enable support access to the site so we could check it.

      To open a ticket please go to this page and select “Tech support -> Create ticket”:

      https://wpmudev.com/live-support/

      To enable support access please go to the “WPMU DEV -> Support -> Support Access” page in your site’s back-end and click on “Grant support access” button there.

      Best regards,

      Adam

  • Antonio
    • Site Builder, Child of Zeus

    Hello Adam

    I have found that the conflict is when editing function.php

    In my installation it contains 2 editing:

    If I write the code suggested at the end of file it doesn’t work, if I write at the beginning it works …

    The second codeine my function.php is related to a child theme plugin install.

    I am not a programmer but I just tried few options and was able to let it work.

    Anyway it could be better to add this function directly into formulator plugin to avoid mess and it is also a MUST HAVE options in many forms.

    Thank you for your support.

  • Adam Czajczyk
    • Support Gorilla

    Hi Antonio

    I’m glad to know that you found the way to make it work. There’s surely the reason for the code working when added in one place but not in other but without seeing the full code of the “functions.php” file I’m afraid I’m not able to pinpoint that reason.

    However, if you made it work I think that’s fine and there’s no need to further troubleshoot it (unless, of course, you want me to).

    But I have suggested adding such validation feature to Forminator in future so our developers will put it under consideration.

    Have a nice day!

    Adam

  • Deb Czajkowski
    • WPMU DEV Initiate

    I too need an “email confirmation” option for certain forms. However, we also have multiple forms with multiple email fields for different purposes. It seems that the code offered above would force every form on the web site with fields named email-1 and email-2 to validate the same way, as a match. I can’t use it without breaking things.

    What would really help would be a few common conditional settings added to the program, that could cover this need and many others. For example, the condition that any specified fields in a form must match could be applied to this problem.

  • Deb Czajkowski
    • WPMU DEV Initiate

    Has this issue been addressed at the plug-in level? Is this a feature we’re likely to see?

    Being able to confirm email is pretty much standard on most forms where you need a working email to provide receipts, etc. I imagine there are other more custom needs to ensure fields match for other reasons.