Hi
Is there an option to confirm email address in the booking form where the customer enters their email address twice and a check is made ?
Thanks
Daniel
Daniel Cooksey
Not by default, but you could add an additional e-mail field
Let’s suppose you gave that field the id _email2
, then you can add a validation check as follows:
function my_validate_email_match( $form ){
if ( is_user_logged_in() ) {
return;
}
$email = $form->get_element( 'email' )->get_value();
$email2 = $form->get_element( '_email2' )->get_value();
if ( $email !== $email2 ) {
$form->get_element( '_email2' )->add_error( 'email-mismatch', "Sorry, your e-mail does not match" );
}
}
add_action( 'eventorganiser_validate_booking_form_submission', 'my_validate_email_match', 10 );
-
This reply was modified 8 years, 1 month ago by Stephen Harris.
-
This reply was modified 8 years, 1 month ago by Stephen Harris.
Stephen Harris
That’s perfect. Unfortunately it throws the booking form error I mentioned in another thread, even when the email addresses match, and which I have confirmed is related to the theme I am using.
Daniel Cooksey
It doesn’t seem to be working. I get the error message all the time. It looks pretty straightforward but my knowledge of PHP is not enough to figure out what is wrong
Daniel Cooksey
What’s the code you’ve used to add the e-mail field to the form?
Stephen Harris
function my_add_element( $form, $event_id ){
//Create element to add to the field
$element = EO_Booking_Form_Element_Factory::create( array(
'type' => 'email',
'id' => '_email2', //a unique ID
'required' => 0, //make this field optional
'label' => 'Confirm Email'
));
//Add the field element, optionally specify where
$form->add_element( $element, array( 'at' => 4 ) );
}
add_action( 'eventorganiser_get_event_booking_form', 'my_add_element', 10, 2 );
-
This reply was modified 8 years, 1 month ago by Daniel Cooksey.
Daniel Cooksey
Sorry Daniel, it was a typo in the code I posted (since corrected). It should have been:
$email = $form->get_element( 'email' )->get_value();
$email2 = $form->get_element( '_email2' )->get_value();
not
$email = $form->get_element( 'email' );
$email2 = $form->get_element( '_email2' );
Stephen Harris
OK it works now for a match but for a mismatch I get the error “Call to a member function add_error() on a non-object “.
So I changed
$email2->add_error( 'email-mismatch', "Sorry, your e-mail does not match" );
to
$form->get_element( '_email2' )->add_error( 'email-mismatch', "Sorry, your e-mail does not match" );
and now it is working
Daniel Cooksey
Sorry about that Daniel. Thanks for posting the correction. I’ve now updated my original post.
Stephen Harris