WordPress Contact Form 7 Plugin - How to save input data into jquery cookie?
-
03-07-2021 - |
Frage
I wonder if there's a way that I can save the user input data from Contact Form 7 into a cookie, preferably the jquery cookie plugin.
By doing so, I can retrieve these values when I visiting some other pages in order to display/re-process these data.
Contact Form 7 contains quite a few files and I am a bit lost. Any ideas or suggestions how to do it? Thanks.
Lösung
Managed to get the form data from CF7 plugin and save it to jQuery cookie.Here's what I have done. ( kind of a quick and dirty way )
Open scripts.js under includes/js/ directory, and find following line of code
$(data.into).find('form').resetForm().clearForm()
This resets the form so form values will be all empty.
Add the custom code before the code mentioned above
For example, if i'd like to save the name
value after email is successfully sent -- We can do this
if(data.mailSent == 1)
{
var name = $('input[name="your-name"]').val();
$.cookie('mycookie_namevalue', name, { path: '/' });
}
your-name
is the default value for name
attribute, or change it to whatever the value specified in CF7 plugin settings.