WordPress Contact Form 7 Howto Hide Empty Fields

Ok., so this took some serious work, but I’ve helped a client on Wizpert hide the empty boxes that were leftover by the form submission using contact-form-7 and the contact-form-7-multipart-module.

What we’ve done is added a function to the scripts.js file of the plugin,

//added a page detection feature so it’s only hiding fields on the completion page.
if( window.location.href.indexOf(“thank-you”) >= 0 ){
// this adds class to p that have no value
$(‘.wpcf7-form p’).each(function(){
var thisText = $(this).text();
if( thisText.indexOf(“:”) >= 0 ){
thisText = thisText.split(“:”);
var thisP = $(this);
if( thisText[1] == ” || thisText[1] == ‘ ‘ ){
$(this).addClass(“hiddenP”);
}
}
});
}
// filter out headings with no p elements below them
$(‘.hiddenP’).css(“display”,”none”);

Thats it,. using pure js

Tags:

Comments are closed.