• Hemant Rathod

    (@hemantathod1590)


    Hello Sir,

    I used CF7 wordpress plugin and one of my client wants to change date field validation. I tried it out by function but it is not wordking.

    add_filter('wpcf7_validate_date', 'custom_date_validation_message', 10, 2);
    function custom_date_validation_message($result, $tag) {
        $tag_name = $tag->name;
    
        if ($result['valid'] === false && $tag_name === 'dates') {
            $result->invalidate($tag, 'Please enter a valid date in the format DD/MM/YYYY.');
        }
    
        return $result;
    }

    My field name is “dates” and input field type is “date”.
    Please help me

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Thread Starter Hemant Rathod

    (@hemantathod1590)

    Hello Sir,

    add_filter( 'wpcf7_validate_date*', 'custom_date_confirmation_validation_filter', 20, 2 );
      
    function custom_date_confirmation_validation_filter( $result, $tag ) {
      if ( 'customdates' == $tag->name ) {
        
        $your_email_confirm = isset( $_POST['customdates'] ) ? trim( $_POST['customdates'] ) : '';
      
        if ( $your_email_confirm == '') {
          $result->invalidate( $tag, "Please enter valid date." );
        }
      }
      
      return $result;
    }

    I used above function for my field [date* customdates id:dates class:form-control class:walcf7-datepicker] but it is not working.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom validation is not working’ is closed to new replies.