I have a form with few fields along with a radio button. This radio button is an optional field. But I am not able to submit form if I do not select any option from the radio button.
<div class="input-field-outer">
[text* your-name class:name placeholder "Name or business name*"]
</div>
<div class="input-field-outer">
[email* email placeholder "Email*"]
</div>
<div class="input-field-outer">
[text* contact-number id:telno class:hs-phone-number placeholder "Contact number*"]
<span id="errmsg"></span>
</div>
<div class="input-field-outer">
<div class="radio-outer">
[radio customer_type "New Customer" "Old Customer"]
</div>
</div>
It will work when I make any of them selected default:
[radio customer_type default:1 "New Customer" "Old Customer"]
Any ideas about using radio button with no items default.
To remove validation on all radio fields add this to functions.php or wherever appropriate.
remove_filter('wpcf7_validate_radio', 'wpcf7_checkbox_validation_filter', 10);
If you want to maintain the required validation for some of the radios, change them to this:
[radio fieldName class:required "Yes" "No"]
Then add this code to functions.php:
remove_filter('wpcf7_validate_radio', 'wpcf7_checkbox_validation_filter', 10);
add_filter('wpcf7_validate_radio', function($result, $tag) {
if (in_array('class:required', $tag->options)) {
$result = wpcf7_checkbox_validation_filter($result, $tag);
}
return $result;
}, 10, 2);
A workaround would be to use a checkbox and add the exclusive parameter. This allows you to submit the form without selecting a customer type.
[checkbox customer_type exclusive "New Customer" "Old Customer"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With