Hi There,
Thanks for the great post and all the comments! I've actually been trying to submit the same form multiple times (but more than twice) to register multiple users using 1 form. I've been successful at submitting the form twice but anything beyond that I can't seem to be able to do it. I've tried many different things and still can't seem to figure it out, my goal is to not have many hidden forms so that I can easily reuse this code for other pages and forms. The forms are being loaded just not via code.
Below is the code that I got from one of SanfordWhiteman's posts. In my form I have a particular field that they can choose the number of users they want to register 1-5 and based on that number different fields will show up for the user to enter First/Last/Email for each.
<!---------------Submitting more than 1 lead------------------------------------->
< script src = "//app-sj01.marketo.com/js/forms2/js/forms2.min.js" ></ script >
< script > // <![CDATA[
MktoForms2 . whenReady ( function ( form )
{
var originalValues ;
var user1LastName ;
var user1FirstName ;
var user1Email ;
form . addHiddenFields ({ '_mkt_trk' : '' });
form . onSubmit ( function ( form )
{
originalValues = form . getValues ();
user1LastName = $ ( 'input[name="flowjoLicenseUserLastName1"]' ). val ();
user1FirstName = $ ( 'input[name="flowjoLicenseUserFirstName1"]' ). val ();
user1Email = $ ( 'input[name="flowjoLicenseUserEmail1"]' ). val ();
});
form . onSuccess ( function ( vals , thankYouURL )
{
this . onSuccess (); // clear onSuccess for 2nd run
this . setValues
({
'LastName' : user1LastName ,
'FirstName' : user1FirstName ,
'_mkt_trk' : '' ,
'Email' : user1Email
});
this . submit (); // send it again
}. bind ( form ));
});
// ]]> </ script >
My goal is tack on a for loop to submit integrate over the number of users needed to be added, as such.
My goal is to use a for loop to iterate over the submission
for ( i = 1 ; i < numberOfLicences ; i ++)
{
console . log ( i )
if ( i == 1 )
{
form . onSuccess ( function ( vals , thankYouURL )
{
//this.onSuccess(); // clear onSuccess for 2nd run
this . setValues
({
'LastName' : user1LastName ,
'FirstName' : user1FirstName ,
'_mkt_trk' : '' ,
'Email' : user1Email
});
this . submit (); // send it again
return false ;
}. bind ( form ));
continue ;
}
else if ( i == 2 )
{
form . onSuccess ( function ( vals , thankYouURL )
{
//this.onSuccess(); // clear onSuccess for 3nd run
this . setValues
({
'LastName' : user2LastName ,
'FirstName' : user2FirstName ,
'_mkt_trk' : '' ,
'Email' : user2Email
});
this . submit (); // send it again
return false ;
}. bind ( form ));
continue ;
}
.... and so on
FYI. numberofLicences is retrieved from user input on the form.
However, this does not seem to work. It feels like the page does refresh but doesn't go do the thank you page, also if I place breaks in the code it also doesn't feel like it's running it. things I'm not too certain of is if all of the different form.onSuccess functions run simultaneously and skips all together the for loop when the form is submitted..a little lost, so all help is welcomed.
Thanks a bunch!
... View more