• Resolved pabloandres86

    (@pabloandres86)


    Hello,
    I would like to know if there is any way to validate an email in a form. When someone signs up, we send them a zoom link to connect to a meeting. The problem is that sometimes they write the mail wrong. Is there a way to verify that it is correct? It would be very useful to be able to validate the mail in a second field, but I didn’t find an option, nor a topic here in the forum.
    Thank you very much in advance
    Pablo

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello @pabloandres86 !

    Hope you’re doing well today!

    We’ve had some requests for that feature, but it’s not available yet out of the box. I’ll add your ticket on the task we have to notify the Forminator team of the interest in this.

    In the meantime, please try the following snippet:

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

    To install:
    – copy the code to a .php file
    – create 2 email fields on the form
    – adjust the values to match your case:

    $use_on_forms = [ 123, 234 ]; // include any number of form IDs where this snippet should be used (you can find those in the URL of the form's edit screen or in the shortcode)
    $field1 = 'email-1'; // make sure those two match your form's fields
    $field2 = 'email-2';

    – create the wp-content/mu-plugins directory if it doesn’t exist
    – upload the snippet to the mu-plugins directory

    Kind regards,
    Pawel

    Thread Starter pabloandres86

    (@pabloandres86)

    Thank you very much, it works. But there is something that I didn’t tell you: I am using a paypal button to submit the form, and I am seeing that it doesn’t validate until after making the payment attempt. Is there a way to validate the mail when touching the paypal button/card button? And don’t wait until the user has already tried to make the payment. I mean before the user has entered paypal or before completing their card details.
    Thanks in advance!

    Thread Starter pabloandres86

    (@pabloandres86)

    or even it would be ideal to validate immediately after placing the second mail

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @pabloandres86

    I am afraid it is not possible out of the box, Forminator will use Ajax to validate the email then submit the form.

    A workaround is using JS for this validation:

    https://gist.github.com/patrickfreitasdev/33a640f653dfad3abb29108557da58e1

    To make it work you need to set two custom classes to Email-1 and E-mail-2

    validate-email-1
    validate-email-2

    https://monosnap.com/file/jSWwUhzlI4Hi9Ne8cJ82y7rFZS7G2V

    This is going to use Load from Ajax event so please make your form render using Ajax:

    https://monosnap.com/file/wOi0R1dX5fhyRBOabex2ZnFlncScuo

    This validates the value of email 1 and email 2 on blur https://www.w3schools.com/jsref/event_onblur.asp

    It also hides the PayPal field until both fields are the same.

    This is just a small sample of code, you can extend it in case you need any extra validations.

    Best Regards
    Patrick Freitas

    Thread Starter pabloandres86

    (@pabloandres86)

    I’ll try it, thank you very much!

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @pabloandres86,

    Sounds good. Please do let us know how that goes. Have a nice day ahead.

    Kind Regards,
    Nithin

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @pabloandres86 ,

    We haven’t heard from you for several days 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 7 replies - 1 through 7 (of 7 total)
  • The topic ‘E-mail adress confirmation’ is closed to new replies.