Forum
Forms app, JS and page refresh
I have a form successfully submitting to the Forms app. I'm trying to prevent the page refresh and want to handle a successful submission with JS.
For the action I've tried action="" which reloads the page, and action="javascript:void(0);" which seems to prevent anything from happening at all. In both cases, the following isn't working:
<perch:success>
<script type="text/javascript">
console.log("YES");
</script>
</perch:success>
I've also tried AJAX:
<perch:success>
<script type="text/javascript">
$.ajax({
type: "POST",
url: "/_contact-form.php",
data: dataString,
success: function() {
console.log("YES");
})
});
</script>
</perch:success>
In all cases, the page simply refreshes. How can I prevent the page refresh entirely and run JS on a successful submission? Thanks!
In your ajax example, are you populating
dataString
?I'm interested in the answer to this
Fred, I've been doing it like this:
Contact form template:
Then, on the page where the form exists, I use this JS (w/ jQuery)
Hope it helps.
I would like to update this thread, because my above post is completely wrong. I realized this when I needed to modify the above code to accommodate file uploads. This is how I'm doing it now:
and the .ajax() options:
If anyone has found a better way, I'm all ears!