This guide will show you how to add an email confirmation field so that the form user must enter their email address twice and they must match.
Step 1
Add two Email elements to your form, if you haven’t done so already. One for the email address and one for the confirm email address.
Step 2
Add the following code to the theme functions.php file (or create a plugin for it).
123 4 5 6 7 8 | add_filter('quform_element_valid_1_4', function ($valid, $value, Quform_Element_Field $element) { if ($valid && $value != $element->getForm()->getValue('quform_1_3')) { $element->addError('The email addresses do not match'); $valid = false; } return $valid; }, 10, 3); |
add_filter('quform_element_valid_1_4', function ($valid, $value, Quform_Element_Field $element) { if ($valid && $value != $element->getForm()->getValue('quform_1_3')) { $element->addError('The email addresses do not match'); $valid = false; } return $valid; }, 10, 3);
- On line 1, change
1_4
to the unique ID of your confirm email element - On line 2, change
1_3
to the unique ID of your first email element
1 2 34 5 6 7 8 910 | function my_confirm_email($valid, $value, Quform_Element_Field $element) { if ($valid && $value != $element->getForm()->getValue('quform_1_3')) { $element->addError('The email addresses do not match'); $valid = false; } return $valid; }add_filter('quform_element_valid_1_4', 'my_confirm_email', 10, 3); |
function my_confirm_email($valid, $value, Quform_Element_Field $element) { if ($valid && $value != $element->getForm()->getValue('quform_1_3')) { $element->addError('The email addresses do not match'); $valid = false; } return $valid; } add_filter('quform_element_valid_1_4', 'my_confirm_email', 10, 3);
- On line 3, change
1_3
to the unique ID of your first email element - On line 9, change
1_4
to the unique ID of your confirm email element
Further customization
You can hide the submitted value for your email confirm element, because it’s just a duplicate. To do that, go to the settings for the confirm email element, and on the Data tab turn off the option Show in email.