• Resolved iritherman

    (@iritherman)


    I want to check the Email address (enter the address again without the option to copy). How can I do it?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Laura – WPMU DEV Support

    (@wpmudev-support8)

    Hi @iritherman

    I hope you’re fine today!

    Currently there’s no “out of the box” e-mail confirmation like this but it can be added with a small bit of custom code. This should do the trick:

    https://gist.githubusercontent.com/adczk/409dba81b8131e21660a39e15f5f5d21/raw/eca09822037d14ba94ac5e5cc515c1d539071fb0/forminator-compare-email-fields.php

    To add it to the site you’d need to add it as an MU plugin:

    – create an empty file with a .php extension (e.g. “forminator-compare-mails.php”)
    – copy and paste that code into it
    – in these lines

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

    replace email-1 and email-2 with your e-mail fields IDs (without brackets)

    `in this line of the code

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

    you should replace email-2 also with ID (without brackets) of one of the e-mail fields of the form (the one you want error to show up) and you can customize error message too.

    – and 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.

    Best regards,
    Adam

    Thread Starter iritherman

    (@iritherman)

    Thank you , i”ll try it.

    Where can I change the css of the form?

    Thread Starter iritherman

    (@iritherman)

    Thank you, it works, but I want the second field of the email to not be filled in by itself and to not be able to copy past.

    Hi @iritherman

    I pinged our SLS team team to review your query and see what can be done in this matter. We will post an update here as soon as more information is available.

    Kind Regards,
    Kris

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @iritherman ,

    Please try this code snippet:

    <?php 
    
    /************************************
    *
    * Forminator - compare two e-mail fields to confirm; if different, issue error
    *
    * by adamcz/WPMU DEV
    * Tested with Forminator 1.15.12
    *
    * Use as MU plugin
    *
    * Adjust fields' IDs if needed to match your form
    *
    *********************************/
    
    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;
    }
    
    add_filter( 'forminator_field_email_markup', function( $html, $id, $required, $placeholder, $value  ) {
    	$field_name = 'email-2'; // Replace this by the target confirmation email field.
    
    	$search = 'name="' . $field_name . '"';
    
    	if ( false === strpos( $html, $search ) ) {
    		return $html;
    	}
    
    	$replace = $search . ' autocomplete="off" oncopy="return false" onpaste="return false" '; 
    	$html    = str_ireplace( $search, $replace, $html );
    	
    	return $html;
    }, 10, 5);

    kind regards,
    Kasia

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Email address confirmation’ is closed to new replies.