I’m using Contact Form 7 on my WordPress site. Unfortunately the plugin doesn’t have “clear fields on click” built in as default which sucks for usability.
I’ve created a theme function to get this working and am nearly there but need someone with better jQuery skills to get everything working as expected. Here’s my code:
// Clear Formfields
function clearfield() {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$(".clearfields").click(function () {
var text = $(this).text();
$(".clearfields").val("");
});
});
</script>
<?php
}
add_action( 'wp_footer', 'clearfield', 100 );
I can’t manipulate the input fields without modifying the plugin but I can add classes. Currently I have:
<input class="clearfields" type="text" value="enter name etc">
Currently this will clear any field with the class .clearfields which is good but I only want to clear just the field the user has clicked in. At the moment it clears everything (name, email, company etc) as all fields have the class applied.
Second to this, with my current setup even though the form appears to send after clicking the submit button the email does not arrive so something is up with my code.
Can anyone help?
Contact Form 7 does have a clear value… just use: watermark
I was facing similarly same issue so i just solve this by created hidden input reset button and triggering with jquery
Html
Jquery
on the latest version of cf7 for wordpress, you can add-in the reset/clear fields button by adding this code:
by default, the reset button will not inherit any style, so it’ll just displayed like normal unstyled button. you can still apply any css styling as shown above.
here is the sample form code to display the “submit” button and “reset” button next to each other with same styles.
live preview here: http://www.ewallzsolutions.com/free-quote/
here is a working example: http://jsfiddle.net/cyVyZ/
HTML Code:
jQuery code:
You can clear on focus default value and on blur get back that value.
Example is here: jsfiddle
jQuery code:
Here is a perfect answer on how to clear textbox values on click in contactform7 .Have a look
http://www.bloggerseed.com/2011/07/clear-text-box-click-contactform-7/
Just add this in Contact Form 7