HTML5 Contact Form 7

Despite being the best contact form solution around for Wordpress, it has never offered support for HTML5 form features, until now.

Contact Form 7 is unquestionably one of my favourite and most used WordPress plugins. You can set up a working contact form in minutes, styling it with CSS is incredibly simple, the form includes jQuery validation and AJAX submission, plus it offers a wide array of different form functionality (inputs, selects, file uploads, etc).

If you haven’t heard of it already, I suggest you check out its listing in the WordPress plugin directory to find out more!

Despite it’s general awesomeness, the creator, as of yet, has not added any support for the new form features in HTML5.

So, I’ve taken it upon myself to add some HTML5 support to the plugin.

New features now include…

  • Ability to add HTML5 “input types” to your input fields. View this video for further info.
  • Support for HTML5 Placeholders.
  • jQuery fallback for browsers that don’t support Placeholders.
  • Existing mess involving line breaks and paragraph tags cleaned up. All layout styling now achieved with CSS.

A step by step guide…

*Remember, you’ll need to be using the HTML5 doctype

First things first, you’ll need to download the plugin ZIP file below, and uncompress it. Then upload the “contact-form-7″ folder to your plugins folder via FTP (/wp-content/plugins).

Download the Plugin

That’s the main job done. If you navigate to the Contact Form 7 setup area in your Dashboard, you’ll notice the additional HTML5 support for inputs and email inputs. Although there is also new HTML5 features for form elements such as select/drop downs, and textareas, I have not really explored this area, as ultimately this project was for my own personal benefit, and all I require at the moment is that support for inputs!

I also advise you to download the CSS styling I’ve come up with, it will make your form look all pretty and stuff (plus it’s dead easy to edit!). One thing to note – add the class “contact-submit” to your submit button.

Download the Form CSS

Just include that CSS in your existing CSS file, or link to it as a new external stylesheet. The CSS will make your form look like this.

Finally, although it’s not a full requirement, it’s probably worth including the fairly lightweight jQuery fallback for HTML5 Placeholders (older browsers don’t support that kinda thing). You can download the JavaScript file below.

Download the Placeholder Fallback

Include the JavaScript file after referencing jQuery in your header.

Then include this snippet of JavaScript AFTER your actual form. (Download the source version here).

<script>
$(function(){
$('input[placeholder], textarea[placeholder]').placeholder();
$('form').submit(function(event) {
event.preventDefault();
$(this).find('input[placeholder]').resetPlaceholder();
$(this).find('textarea[placeholder]').resetPlaceholder();
return false;
});
});
</script>

The job’s a done’un. If you need any help with setting it up, feel free to contact me using the comments area below. Remember, after installing this fix, don’t update the plugin as you will lose the HTML5 functionality (until the creator hopefully adds HTML5 support).

Discussion and Debate

  1. Joe Wilcox on May 15, 2011 at 11:54 am

    Nice one Jack, Ill be using this from now on!

  2. Oiva on May 17, 2011 at 8:58 am

    I installed the plugin on WordPress 3.1.2 but the tag generator doesn’t seem to work. Or I think there should be a thing called tag generator, as the settings page has an empty div#taggenerator and your screenshot shows a tool that looks like it could generate tags :)

  3. Jack on May 17, 2011 at 10:26 pm

    Hi Oiva,

    Not too sure where you’re going wrong. The process (to put it simply) is…

    1. Download plugin, and upload to your plugins folder.
    2. Activate plugin in your dashboard.
    3. Navigate to “Contact” settings, which will appear on your admin navigation.
    4. Click “Generate Tag”, select text field or email field.
    5. When adding a new input/email box, you should have a module named “html5 input type?” (as shown in the screenshot). This is where you type your required input type.

    Give me a shout if you’re still having problems.

  4. bigandy on May 26, 2011 at 10:26 pm

    Hi Jack,

    I like the fact that you have converted the contact form 7 -> HTML5! I do, however, have a gripe. Wrapping each input in tags is not a good idea because they are an inline element, would it be poss to change to s?

    Cheers,
    bigandy

  5. Jack on May 27, 2011 at 6:38 am

    Morning Andy,

    Are you referring to the span tags that wrap around each input?

    Unfortunately the core Contact Form 7 function uses these span wraps with it’s validation (and I didn’t want to spend that long editing it!).

  6. Oli on September 26, 2011 at 3:20 pm

    Thanks Mate!
    I’ll use it in my next project!

  7. Jack on September 30, 2011 at 10:24 am

    Glad you’ve found it useful Oli!

  8. Navaneetha Krishnan on February 16, 2012 at 9:16 am

    Wow.. This is an wonderful post. I search long days. I stop search today. Because its works fine. Thanks dude. I dont know such a superv word thank to you.. Great job…

  9. Nicole on March 14, 2012 at 3:59 pm

    This is great! However I can’t seem to put in a placeholder for a textarea (only input fields)…any advice?

  10. Nicole on March 14, 2012 at 4:04 pm

    Oh actually:


    [textarea your-message watermark "Your Message"]

  11. Chris on March 19, 2012 at 8:53 pm

    Hi, nice!! But once it is installed and I update to current contact form 7, html5 options disappears. Is possible add html5 features to current ContactForm 7 version? Thanks. i’m sorry my poor English

  12. Jack on March 27, 2012 at 11:52 pm

    Chris – yep, unfortunately that’ll happen if you do upgrade! If I get the time I will add my fixes to the latest version, although the creator does like to ship updates fairly often.

  13. Rob on April 15, 2012 at 5:34 pm

    This is great – works perfectly and does exactly what I need. Contact Form 7 has been my go-to contact plugin for a long time, but I’ve been frustrated with the lack of HTML5 support. Thanks for doing this!

  14. Jack on May 3, 2012 at 7:33 pm

    No problem Rob, thanks for the message!

Leave your thoughts...