Ask to verify email?

This topic contains 4 replies, has 2 voices, and was last updated by  Dan Skinner 9 years, 10 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #16691

    Following an event that we’ve just held, we heard from a few too many people that they hadn’t received the confirmation email. This could obviously have been for a number of reasons, but as I’m not insisting that they register an account, I’d like to be sure that they’ve at least entered a valid email address.

    Is there a way of adding a second ‘verify Email’ field to a booking form that won’t allow people to submit the booking until the 2 emails entered match?

    Dan Skinner
    #16698

    Hi Dan,

    As you’re aware the plug-in doesn’t add a second, ‘confirm your e-mail’ field (perhaps it should), but you can do it with the following:

    function my_add_element( $form, $event_id ){    
    
        //Get existing email field
        $email = $form->get_element( 'email' );
        if( !$email ){
             return;
        }
    
        //Create element to add to the field
        $element = EO_Booking_Form_Element_Factory::create( array(
             'type'     => 'email',
             'id'       => '_confirm_email', //a unique ID
             'required' => 1, //make this field required
             'label'    => 'Please confirm your e-mail'
       ) );
    
       //Add the field element, immediately below $email field
       $form->add_element( $element, array(
           'at' => $email->get( 'position' ) + 1, 
           'parent' => $email->get_parent()
       ) );
    }
    add_action( 'eventorganiser_get_event_booking_form', 'my_add_element', 10, 2 );
    

    Code to validate confirmed e-mail address

    function my_validate_element( $form ){
    
         $email= $form->get_element( 'email' );    
         $email2 = $form->get_element( '_confirm_email' );
    
         if( $email && $email->get_value() !== $email2->get_value() ){
               $email2->add_error( 'email-mismatch', "Emails do not match." );
         }
    
    }
    add_filter( 'eventorganiser_validate_booking_form_submission', 'my_validate_element', 10 );
    
    Stephen Harris
    #16699

    Fab – thanks for the code. Great to know that this kind of stuff can be supported.

    Where are these 2 sections augmented to?

    NB. I do not currently have templates enabled.

    Cheers,

    Dan

    Dan Skinner
    #16700

    Ideally in a utility plugin, but it will work in theme’s functions.php ( See http://wp-event-organiser.com/blog/tutorial/where-should-i-put-code-from-the-tutorials/ for details).

    It doesn’t require the plugin templates to be enabled.

    Stephen Harris
    #16701

    Fantastic – works like a charm 🙂

    Many thanks Stephen.

    Dan Skinner
Viewing 5 posts - 1 through 5 (of 5 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.