Required Radio Button Validation Solution
-
If you are looking for an ‘easy’ way to make sure that radio buttons are required. Check this out:
function custom_cf7_required_radio_filter($result, $tag) { $name = $tag['name']; if ( $tag['type'] == 'radio' //&& substr($name, -9) == '-required' && empty($_POST[$name]) ) { $result['valid'] = false; $result['reason'][$name] = 'Please fill in this required field'; } return $result; } add_filter('wpcf7_validate_radio', 'custom_cf7_required_radio_filter', 10, 2);
As is it will make all radio buttons required. If you want some fine control uncomment this line:
//&& substr($name, -9) == '-required'
, and then add -required to your field names.Make sure you if go this route that you update the field names is all locations ie email body, third party submission, or what have you.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Required Radio Button Validation Solution’ is closed to new replies.