Title: Form validation
Last modified: March 10, 2020

---

# Form validation

 *  [Pamela](https://wordpress.org/support/users/infoknutsford-softwarecouk/)
 * (@infoknutsford-softwarecouk)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/form-validation-17/)
 * If you click on “Know exactly what you want?” all the radio box lines have a 
   red x when you send the form even if a value is selected adn I can’t see why
 *     ```
       add_action('init','validate_radio');
       function validate_radio() {
       	remove_filter( 'wpcf7_validate_radio',
       	'wpcf7_checkbox_validation_filter', 10, 2 );
       	add_filter( 'wpcf7_validate_radio',
       	'radio_validation_filter', 10, 2 );
       }
   
       function radio_validation_filter( $result, $tag ) {
   
       	$name = $tag->name;
   
       	$whatyouwant = isset( $_POST['whatyouwant'] ) ? trim( $_POST['whatyouwant'] ) : '';	
   
       	$is_required = $tag->is_required() || $whatyouwant[0] !== "";
       	$value = "";
       	if (isset( $_POST[$name]))  {
       		$value = $_POST[$name];
       	}
   
       	if ( $whatyouwant !== "" & $value == "" ) {
       		$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
       	}
   
       	return $result;
       }
       ```
   
 * Is what I have added to the functions.php file
 * It doesn’t look as though $value is being set but I might be wrong
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fform-validation-17%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

The topic ‘Form validation’ 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

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

 * 0 replies
 * 1 participant
 * Last reply from: [Pamela](https://wordpress.org/support/users/infoknutsford-softwarecouk/)
 * Last activity: [6 years, 3 months ago](https://wordpress.org/support/topic/form-validation-17/)
 * Status: not resolved