Title: Multiple dynamic dropdown fields
Last modified: August 22, 2019

---

# Multiple dynamic dropdown fields

 *  [rocket.works – Dominik Friedrich](https://wordpress.org/support/users/rocketworks/)
 * (@rocketworks)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/multiple-dynamic-dropdown-fields/)
 * 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](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/multiple-dynamic-dropdown-fields/#post-11862621)
 * See [https://contactform7.com/2015/03/28/custom-validation/](https://contactform7.com/2015/03/28/custom-validation/)
 *  Thread Starter [rocket.works – Dominik Friedrich](https://wordpress.org/support/users/rocketworks/)
 * (@rocketworks)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/multiple-dynamic-dropdown-fields/#post-11907158)
 * 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.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [custom-validation](https://wordpress.org/support/topic-tag/custom-validation/)
 * [dropdown](https://wordpress.org/support/topic-tag/dropdown/)

 * 2 replies
 * 2 participants
 * Last reply from: [rocket.works – Dominik Friedrich](https://wordpress.org/support/users/rocketworks/)
 * Last activity: [6 years, 8 months ago](https://wordpress.org/support/topic/multiple-dynamic-dropdown-fields/#post-11907158)
 * Status: not resolved