booking form option – confirm email

WordPress Event Management, Calendars & Registration Forums General Question booking form option – confirm email

This topic contains 8 replies, has 2 voices, and was last updated by  Stephen Harris 8 years, 1 month ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #25397

    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
    #25401

    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
    #25408

    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
    #25412

    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
    #25430

    What’s the code you’ve used to add the e-mail field to the form?

    Stephen Harris
    #25434
    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
    #25463

    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
    #25531

    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
    #25558

    Sorry about that Daniel. Thanks for posting the correction. I’ve now updated my original post.

    Stephen Harris
Viewing 9 posts - 1 through 9 (of 9 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.