Support » Plugin: Contact Form 7 » [Plugin: Contact Form 7] Adding class to form tag

Viewing 8 replies - 1 through 8 (of 8 total)
  • Gary Darling

    (@garydarling)

    Try editing this file and adding your class here. This will get overwritten next time you update the plugin, so you may want to save it as a snippet somewhere:
    contact-form-7/includes/classes.php
    The part that adds the existing form class:

    /* Generating Form HTML */
    
    	function form_html() {
    		$form = '<div class="wpcf7" id="' . $this->unit_tag . '">';

    Thread Starter scalzo

    (@scalzo)

    Thank you for the quick support.

    I tried to change the class from the snippet you provided. I also tried to change the variable further down pertaining to class. However neither of these changes worked. I looked at the page source code and it shows the class in the right spot but it seems something is overriding the class I am adding.

    <p><div class="wpcf7" id="wpcf7-f60-p4-o1"><form action="/contact/#wpcf7-f60-p4-o1" method="post" class="box style">
    <div style="display: none;">
    <input type="hidden" name="_wpcf7" value="60" />
    <input type="hidden" name="_wpcf7_version" value="3.1.1" />
    <input type="hidden" name="_wpcf7_unit_tag" value="wpcf7-f60-p4-o1" />
    <input type="hidden" name="_wpnonce" value="71ccf26a68" />
    </div>
    Gary Darling

    (@garydarling)

    Can you post a link to your site?

    Thread Starter scalzo

    (@scalzo)

    This is just a development site -> http://www.portalbernicomputers.info/contact/

    Gary Darling

    (@garydarling)

    I’m not seeing the classes you created in any of your style sheets. FYI, box and style, with a space between are two separate classes. If you want it to be one class you need a dash in there like this: box-style. But I didn’t see that class either.

    Thread Starter scalzo

    (@scalzo)

    Thank you again for your time. The themes typography example page uses the following code to output the demo form with styling.

    <form action="#" class="box style">

    It seems to work without the use of contact form 7.

    I may just code the form if I cannot figure it out.

    hello,

    A bit late may be but I think you are having the issue because the filter hook is changing the class value before sending it to the browser.
    I wanted to change the class as well for the form tag and got the same issue.
    But if you change the line that calls the filter in contact-form-7/include/classes.php like this:

    `$class = apply_filters( ‘wpcf7_form_class_attr’, ‘class-you-want’ );

    This modification did the trick for me…
    Hope this help

    Thanks,

    viraks hint also worked for me!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: Contact Form 7] Adding class to form tag’ is closed to new replies.