• Resolved retroriff

    (@retroriff)


    Hello,

    I am using CodyHouse frameworks and I need to add some classes directly to the form elements. I see that I can add classes to wrapper divs, but this forces me to create custom rules. Is there any filter, setting or option that allows me to add classes to each form elements?

    Thank you

Viewing 1 replies (of 1 total)
  • Plugin Support Ethan Choi

    (@ethanchoi)

    Hi @retroriff,

    You can consider starting with the following snippet to add classes to form input fields. In the example, we’re applying wpforms-custom-css-class so you’ll have to replace that with your CSS class(es).

    function wpf_dev_add_custom_class() {
        ?>
        <script type="text/javascript">
            var fields = document.querySelectorAll(".wpforms-form input, .wpforms-form select, .wpforms-form textarea");
    		fields.forEach(function(field){
    			field.classList.add("wpforms-custom-css-class");
    		});
        </script>
        <?php
    }
    add_action( 'wpforms_wp_footer', 'wpf_dev_add_custom_class' );
    

    In case it helps, here’s our tutorial with the most common ways to add custom code like this.

    For the most beginner-friendly option in that tutorial, I’d recommend using the Code Snippets plugin.

    Hope this helps!

Viewing 1 replies (of 1 total)

The topic ‘Hw to add classes to the input elements?’ is closed to new replies.