• Hello!

    I have a complicated problem.

    I have a from, with 3 dropdown fields. The user has to select something from the first dropdown and the dropdown below will unlock (and so on) and custom options getting filled in via javascript.

    I managed to create a custom field, that is displaying all 3 dropdown fields and they are working great. I even get the results send via email.

    The problem I have is, that the the fields need to be required. I tried to implement a custom validation. It gets triggered correctly, but I cant invalidate the result.

    Even with the following code, the user can still submit the form. It seems the invalidate functionn of the $result class is not working.

    Test code:

    function custom_dropdown_validation( $result, $tag ) {
    
    	$result->invalidate( $tag, "This field ins invalid!" );
    	
    	return $result;
    }

    What do I do wrong? Is there a better solution?

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

    (@takayukister)

    Hello Takayuki,

    thanks for the fast replay.

    I just tried it again. I followed the tutorial, the validator gets called correctly, but the $result->invalidate seems not to work. The form gets sent anyways.

    Here is my simplified example code:

    
    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 ); 
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Multiple dynamic dropdown fields’ is closed to new replies.