Contact Form 7 Radio and Checkbox in Bootstrap 4 Style

Are you using Contact Form 7 plugin in a WordPress website using a theme built with Bootstrap front-end framework? Then you must have faced styling issues in CF 7 inputs in accordance with Bootstrap. Creating Contact Form 7 radio and checkbox using the form template doesn’t allow adding classes as per Bootstrap documentation.

Contact Form 7 is a popular plugin, widely used in WordPress websites. Bootstrap 4 is also a fantastic framework to create responsive websites. Further, there are a number of WordPress themes that use CF7 and BS4 together.

Contact Form 7 Radio and Checkbox in Bootstrap 4 Style

Still, a few issues arise when you create a BS4 form using the CF7 interface in WordPress admin panel. However, there are easy fixes for CF7 and BS4 combination issues for forms in WordPress websites. Like, use this fantastic CSS solution to improve the appearance of Contact Form 7 validation errors.

Contact Form 7 Radio and Checkbox – Problem for Bootstrap 4

We have used version 5.0 of CF7 and 4.1 of Bootstrap during the writing of this article. A typical checkbox markup is as follow according to Bootstrap documentation:

And following is the markup for a checkbox field in CF7:

Now try to add classes to checkbox or radio field in the template and check the rendered markup. It won’t get success to apply BS4 classes adequately. Since Bootstrap labels, checkboxes and their parents, each needs their own class.

Bootstrap 4 Style in Contact Form 7 Radio and Checkbox

Here we have jQuery solution to style the checkbox and radio button fields. Since it’s a WordPress website as well as Bootstrap theme. So jQuery should be available in your CF7 pages. First of all, you need to place the following script in your theme’s JS file (without script tag). Alternatively, you can add these lines in the footer.php file of your active theme after the wp_footer() function.

Here you see 3 variables, the first one adds the given class to the label. Leave the astx_label_class variable empty if you don’t want to add or hasn’t the label associated. The second variable adds the class to the checkbox or radio itself. And the last variable is to add the class to the input’s parent. Also, you can specify multiple classes using space as shown.

Finally, our form mark up will look like:

Did this solution resolve your issue regarding styling Contact Form 7 radio and checkbox as Bootstrap 4 style? Do you have any trouble regarding combining Bootstrap 4 and Contact Form 7? We’re here to assist you. Also, don’t forget to check what we offer at the sidebar in the right.

You Might Interested In

Leave a Reply