I’ve tried searching but this only returns results on how to AJAX load a page/form.
What I am doing is loading a form via AJAX (Contact Form 7) and I would like to know how to re-enable AJAX submission on that form. Is this a possibility with CF7?
Leave a Reply
You must be logged in to post a comment.
Contact Form 7 calls an init function, which executes on page load. If your form is loading using AJAX, you should make sure that the function gets called after your form is loaded.
Look into:
plugins/contact-form-7/includes/js/scripts.js
for the definition of the function
wpcf7InitForm
.Edit:
Calling this function inserts a new loading logo each time. Unfortunately, I couldn’t find a better solution than deleting the duplicate loader from DOM using jQuery:
this behavior changed with version 4.8 of wpcf7. since then the call would be
while it does not require jQuery anymore, you could also pass a node..
somehting like this (capable of multiple forms..)
it is still written in jQuery, but it does not have to be active (i.e. jQuery.ready()) in your function to operate. plus it got rid of jQuery.form
Use the following code for version 5.4 or above:
Put this in your ajax response. This will re-initialize all forms
I spent the last three hours looking for a solution to this and I only have found questions without answer, but I think I found a solution and hope this will help you and other people with this problem.
In my case, i was trying to embed a CF7 form in an inline lightbox with PrettyPhoto (but I think this is the same with others like Fancybox). My problem was that these inline lightboxes works generating the content inside the lightbox via AJAX, and the CF7 scripts were loaded before that content, so the AJAX submit of the form wasn’t work.
What I did was getting the CF7 scripts via jQuery.get on the event triggered when a prettyphoto lightbox is opened. In your case, I think you should do this just after generating the content via AJAX, something like:
Make sure that your paths and versions are the same, otherwise change them.
This will refresh the form and re-enable the AJAX submit.
Hope it helps!
Was unable to send the form via ajax with the above comments. I had to use the
wpcf7.submit
method vswpcf7.init
Example usage: