Title: selective form validation
Last modified: January 18, 2017

---

# selective form validation

 *  [Ghostflasher](https://wordpress.org/support/users/ghostflasher/)
 * (@ghostflasher)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/selective-form-validation/)
 * Hi,
 * is there a possibility to activate field validation depending on a checkbox? 
   I have created a form with input fields which are only active when a checkbox
   is checked. Now I want that these fields are mandatory when the checkbox is checked
   and that they will be mentioned in the error display. When the checkbox is not
   checked, these fields should be kept out of the validation.
 * Is there a way to inject this data into your validation process?
 * thx for your help
    dan

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/selective-form-validation/#post-8670347)
 * There are three ways this is possible. The first is to use a regex that will 
   accept a blank alternative, so that the field can either be blank or meet the
   regex pattern.
 * That is an easy way to go, but does not force the user to fill in the field, 
   it only forces them to fill it in with a certain kind of information or nothing.
 * The rest will require some coding knowledge:
 * you can create a custom validation method using the Participants Database API
 * you can use a custom template with javascript to conditionally require the field
   be filled in
 *  Thread Starter [Ghostflasher](https://wordpress.org/support/users/ghostflasher/)
 * (@ghostflasher)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/selective-form-validation/#post-8715659)
 * Hi,
 * thanks for your reply. I checkt the API but don’t understand to use it actually.
   Do u have an examplecode for “pdb-before_validate_field”?
 * best regards
    dan
 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/selective-form-validation/#post-8717115)
 * I posted a tutorial on setting up a custom validation:
 * [Custom Field Validation](https://xnau.com/custom-field-validation/)
 *  Thread Starter [Ghostflasher](https://wordpress.org/support/users/ghostflasher/)
 * (@ghostflasher)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/selective-form-validation/#post-8717482)
 * Thank you! I’ll check it out tomorrow morning!
 *  Thread Starter [Ghostflasher](https://wordpress.org/support/users/ghostflasher/)
 * (@ghostflasher)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/selective-form-validation/#post-8721164)
 * How can I let a fields validation pass, when another field is checked?
 * e.g.
 *     ```
       if( $field->name === 'field_a') {
       ```
   
 *  if( $field->value == ‘yes’ ) {
 *     ```
         /* code to set field_b->error_type = 'valid'
       ```
   
 *  }
    `}
 *  Thread Starter [Ghostflasher](https://wordpress.org/support/users/ghostflasher/)
 * (@ghostflasher)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/selective-form-validation/#post-8721170)
 * sorry, formating got messed up
 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/selective-form-validation/#post-8721467)
 * This is where you would access the $_POST array, it will contain all the values
   that are getting submitted at that point. You would check that array for the 
   value of the other field.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘selective form validation’ is closed to new replies.

 * ![](https://ps.w.org/participants-database/assets/icon-256x256.jpg?rev=1389807)
 * [Participants Database](https://wordpress.org/plugins/participants-database/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/participants-database/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/participants-database/)
 * [Active Topics](https://wordpress.org/support/plugin/participants-database/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/participants-database/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/participants-database/reviews/)

## Tags

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

 * 7 replies
 * 2 participants
 * Last reply from: [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/selective-form-validation/#post-8721467)
 * Status: not resolved