• Resolved WebBuddy

    (@websprout)


    Hi,

    First, thank you for this great plugin!

    Next, I am having two fields (Start Time & End Time) in my contact form. Is it possible for this plugin to detect if the user selects a End Time earlier than Start Time, then it prompts an error?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @websprout unfortunately this is not possible in the current version of the plugin. Sorry for this limitation.

    Thread Starter WebBuddy

    (@websprout)

    Thank you for your reply, Carlos.

    I managed to find a custom validation article on contact form 7 and it teaches me to code the following to check if end date is earlier than the start date. Just posting here in case in future others may need it:

    
    // to check if form end date is earlier than start date
    add_filter( 'wpcf7_validate_text', 'custom_email_confirmation_validation_filter', 20, 2 );
     
    function custom_email_confirmation_validation_filter( $result, $tag ) {
        if ( 'enddate' == $tag->name ) {
                   
            $dateTimestamp1 = strtotime($_POST['startdate']); 
            $dateTimestamp2 = strtotime($_POST['enddate']); 
            
            if ( $dateTimestamp1 > $dateTimestamp2) {
                $result->invalidate( $tag, "End date cannot be earlier than Start date!" );
            }
        }
     
        return $result;
    }
    

    The article for reference is at – https://contactform7.com/2015/03/28/custom-validation/

    Carlos Moreira

    (@carlosmoreirapt)

    Thank you @websprout
    That will be helpful to others for sure.
    Greetings, Carlos

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Date / time validation?’ is closed to new replies.