Title: Custom Validation Problem
Last modified: October 5, 2017

---

# Custom Validation Problem

 *  [JohnStaples](https://wordpress.org/support/users/johnstaples/)
 * (@johnstaples)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/custom-validation-problem/)
 * I am trying to get custom validation to work on checkboxes and following your
   email fields example. But in my custom validation function for some reason $tag-
   >name has no value when passed to the function. So the only way I could get it
   to work was by removing the test for the tag name (show below commented out).
   The problem with that is, of course, now it triggers regardless of which field
   is being validated and shows an error for every checkbox.
 * Any idea what might be going wrong? Thanks in advance for any help!
    —————– add_filter(‘
   wpcf7_validate_checkbox’, ‘custom_checkbox_confirmation_validation_filter’, 20,
   2 );
 * function custom_checkbox_confirmation_validation_filter( $result, $tag ) {
    //
   if ( ‘checkbox-1’ == $tag->name ) { $checkbox_1 = isset($_POST[‘checkbox-1’])&&
   $_POST[‘checkbox-1’] ? “1” : “0”; $checkbox_2 = isset($_POST[‘checkbox-2’]) &&
   $_POST[‘checkbox-2’] ? “1” : “0”; $checkbox_3 = isset($_POST[‘checkbox-3’]) &&
   $_POST[‘checkbox-3’] ? “1” : “0”; if ( $checkbox_1 == 0 && $checkbox_2 == 0 &&
   $checkbox_3 == 0 ) { $result->invalidate( $tag, “You must check at least one 
   box! ” . $tag->name); } //} return $result; }

The topic ‘Custom Validation Problem’ 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-validation](https://wordpress.org/support/topic-tag/custom-validation/)

 * 0 replies
 * 1 participant
 * Last reply from: [JohnStaples](https://wordpress.org/support/users/johnstaples/)
 * Last activity: [8 years, 7 months ago](https://wordpress.org/support/topic/custom-validation-problem/)
 * Status: not resolved