• 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.

    https://www.ads-software.com/plugins/contact-form-7/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thank you. This helped me a lot.

    Where does this go?

    Thread Starter [email protected]

    (@andrewclickzoomcom)

    This function goes in functions.php

    So, interestingly I did put this function in my functions.php file. However, now when I fill out the form, even when I check the radio buttons it won’t let me submit it because it’s saying “Please fill in the required field.” Well, this might explain why they’re not getting sent. The only problem is that I’m filling them in. How is it not recognizing that?

    Awesome! .. This should go into CF7 permanently. Since radio buttons, when used are a mandatory selection. When no default is set, a validation error should raise.

    Thanx again for this beautiful snippet!

    thank you for this code

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Required Radio Button Validation Solution’ is closed to new replies.