Yup, that makes sense. Contact Form 7’s JS functionality automatically clears the values after form submission. CF7 DTX is pure PHP right now, so it doesn’t have any control over any changes that are made client-side.
If you wanted to keep certain fields from clearing, you could overwrite the clearform function, which looks like this:
$.fn.clearForm = function() {
return this.each(function() {
$('input,select,textarea', this).clearFields();
});
};
For example, to keep it from clearing hidden fields (those made with [dynamichidden]), you could write something like this jQuery function (untested):
$.fn.clearForm = function() {
return this.each(function() {
$('input,select,textarea', this).not('input:hidden').clearFields();
});
};
Assuming you loaded it after CF7’s javascript, this should overwrite the function I believe.
I’ll look into including this functionality in the next release of CF7 DTX 🙂
By the way, instead of applying the ‘hidden’ class to your fields, it is probably better to use the dynamichidden tag (available in the latest version of CF7 DTX).
Hope that helps,
Chris
Thanks Chris, this help me a lot! I don’t know much about Javascript, how can I change your function to DON’T clear the fields with an specific class, like “dontclear”?
I tried it:
$.fn.clearFields = $.fn.clearInputs = function() {
return this.each(function() {
var t = this.type, tag = this.tagName.toLowerCase();
if (t == 'text' || t == 'password' || tag == 'textarea') {
if($(this).hasClass('dontclear')){
this.value = this.value;
} else {
this.value = '';
}
}
else if (t == 'checkbox' || t == 'radio') {
this.checked = false;
}
else if (tag == 'select') {
this.selectedIndex = 0;
}
});
};
But isn’t working…
Thanks!
I would just change the selector in the clearForm function:
$.fn.clearForm = function() {
return this.each(function() {
$('input,select,textarea', this).not('.dontclear').clearFields();
});
};
The .not() removes elements with the dontclear class from the set of elements to clear.
Just make sure the script with this function runs after the CF7 script, and inside a jQuery(document).ready()
I was trying to edit the original jquery.form.js from CF7, should work, right?
$.fn.clearForm = function() {
return this.each(function() {
$('input,select,textarea', this).not('.dontclear').clearFields();
});
};
I tried that on the original JS and didn’t work. =/
Hi Leo,
I’m currently away with limited access, but I’ll add this to my do list to figure out, hopefully this week. I’ll let you know what I figure out.
Don’t worry sevenspark, I found the problem. Even adding this code the form keeps being cleared. I hed to remove the “.resetForm()” from scripts.js.
if (1 == data.mailSent) {
$(data.into).find('form').resetForm().clearForm();
Now it’s working. Sadly I had to change the original code.
Thanks!
I’ve removed the .resetForm() from the CF7 scripts.js as well, but it didn’t solve the refresh issue for me. All the fields, including the dynamic fields still refresh. Any ideas?
Anyon knows how to add a dynamic textarea??
like [dinamictext xxx “CF7_GET key=’item_link'”]
???
Anyon knows how to add a dynamic textarea??
like [dinamictext xxx "CF7_GET key='item_link'"]
???
I concur.
@lassepappa, @paul Sputnik,
CF7 DTX doesn’t currently support text areas, only text inputs.
If you’re referring to text inputs and are having trouble with that code, you should make sure you are using the correct tag names – e.g., it’s “dynamictext” not “dinamictext” 🙂