The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Fire JS After Form Submission With Redirect

Labels

This Discussion is public

Notifications

Hi I'm a little stuck and would love some help.

How do I fire a JS snippet after a form is submitted before it redirects?

I need to trigger this snippet:

<script type="text/javascript">window.funnelytics.events.trigger('complete-form', {First Name: 'qh4icy2',Last Name: 'ocfup12',Rate: 'ywe8n',Country: 'nh5lo',Content Type: 'm6b8t',}, function() {// continue with process..});</script>

I've seen this: https://formidableforms.com/knowledgebase/javascript-examples/javascript-after-form-submit/#kb-before-redirect, but don't quite get how to combine the scripts.Would I just put this:
<script>
jQuery(document).ready(function($){
$(document).on( 'frmBeforeFormRedirect', function( event, form, response ) {
var formID = $(form).find('input[name="form_id"]').val();
});
});
window.funnelytics.events.trigger('complete-form', {
First Name: 'qh4icy2',
Last Name: 'ocfup12',
Rate: 'ywe8n',
Country: 'nh5lo',
Content Type: 'm6b8t',
}, function() {
// continue with process..
});
</script>

After the fields in Custom HTML?

 

Any help is appreciated.

Alex

You would replace this code:

var formID = $(form).find('input[name="form_id"]').val();

with your script.

jQuery(document).ready(function($){
$(document).on( 'frmBeforeFormRedirect', function( event, form, response ) {
window.funnelytics.events.trigger('complete-form', {
First Name: 'qh4icy2',
Last Name: 'ocfup12',
Rate: 'ywe8n',
Country: 'nh5lo',
Content Type: 'm6b8t',
}, function() {
// continue with process..
});
});
});

Thanks! That's awesome. :-) Can't wait to get this working.

Juist got stuck:

Would I have:

jQuery(document).ready(function($){
$(document).on( 'frmBeforeFormRedirect', function( event, form, response ) {
window.onload = function() {
window.funnelytics.events.trigger('complete-form', {
First Name: 'qh4icy2',
Last Name: 'ocfup12',
Rate: 'ywe8n',
Country: 'nh5lo',
Content Type: 'm6b8t',
}, function() {
});
};
});
});

OR 'document.getElementById'

jQuery(document).ready(function($){
$(document).on( 'frmBeforeFormRedirect', function( event, form, response ) {
window.onload = function() {
window.funnelytics.events.trigger('complete-form', {
first_name: document.getElementById("field_qh4icy2").value,
last_name: document.getElementById("field_ocfup12").value,
rate: document.getElementById("field_ywe8n").value,
content_type: document.getElementById("field_m6b8t").value,
country: document.getElementById("field_nh5lo").value,
}, function() {
});
};
});
});

Not sure what format to use.

Thanks

Alex

I have this:

https://pastebin.com/ehSVHK9N

 

But can't pick up the event 'complete-form' much less any variables. Any idea what I'm doing wrong?

Where did you find the instructions for integrating funnelytics? Are you loading he funnelytics scripts properly? Whatever the complete-form event is, it's part of funnelytics, not Formidable.

Also, Formidable doesn't have variables of the names you reference unless you created them specifically.

Since you are using jQuery, assuming the field names are correct, the values of the fields would be:

first_name: $("#field_qh4icy2").val(),
last_name: $("#field_ocfup12").val(),
rate: document.$("#field_ywe8n").val(),
content_type: $("#field_m6b8t").val(),
country: $("#field_nh5lo").val(),

That's about all I'll be able to help you with. As to why you're not seeing the funnelytics events, I suggest you ask funnelytics support.That would have nothing to do with Formidable.

Thanks! I'll ask FL about this. They gave me the script and wanted it to load after a form is submitted.

 

Many thanks for your help!

Discussion closed.