• I’m still have problems with the custom validation.

    According to the tutorial, this should work. But it seems $result->invalidate is not working with a simple custom from tag.

    Tutorial I used (together with the previous article): https://contactform7.com/2015/03/28/custom-validation/

    Here is the testcode I created in my plugin:

    add_action( 'wpcf7_init', 'rw_add_form_tag_kursdropdown' );
     
    function rw_add_form_tag_kursdropdown() {
    		wpcf7_add_form_tag( 'kursauswahldropdown', 'rw_kurs_dropdpow_form_hander' );
    }
     
    function rw_kurs_dropdpow_form_hander( $tag ) {
    	$atts = array(
    		'type' => 'text',
    		'name' => 'kurs',
    	);
    
    	$input = sprintf(
    			'<input %s />',
    			wpcf7_format_atts( $atts ) );
    
    	return $input;
    }
    
    function rw_kurs_dropdown_validation( $result, $tag ) {
    	if ( 'kursauswahldropdown' == $tag->type ) {
    		$result->invalidate( $tag, "Are you sure this is the correct address?" );
    	}
    
    	return $result;
    }
    
    add_filter( 'wpcf7_validate_kursauswahldropdown', 'rw_kurs_dropdown_validation', 1, 2 ); 

    I testet it, the condition is met, so the field should be invalid. However nothing happens and the result seems to be unchanged.

    What did I do wrong?

    Thanks in advance!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Validation not working (anymore)’ is closed to new replies.