Form v2 addHiddenFields()
I'm in the process of switching to Form 2.0. I was able to make it works by submitting the form in the background IF I'm using this:
form.addHiddenFields({ "Email": $('#Email').val(), "Phone": $('#Phone').val() });
However, to avoid listing all the fields manually like above, I'd want something more flexible to accommodate different and longer forms, I have something like below, which outputs a JSON-like format.
Basically I have one array to hold the Field name, another array to hold the Field value, then a combined array to output a json-like string. Then use that string for addHiddenFields(), but things didn't work - there's no js error, and my alert show the string in correct format. The form went through but values were not recorded. Thanks for your input - what's wrong in my codes or whether there's a better way to do this.
var formLabels=[]; var formVals=[]; var formString=[]; var formFieldCount;
$('.mkto input,.mkto select, .mkto textarea').each(function(){
formLabels.push($(this).attr('name'));
formVals.push($(this).val());
})
formFieldCount = $('.mkto input').length + $('.mkto select').length + $('.mkto textarea').length;
for (i=0; i<formFieldCount; i++){
formString.push('"'+formLabels[i]+'": '+'"'+formVals[i]+'"');
}
// formString = '{'+formString+'}';
// alert(formString);
form.addHiddenFields(formString);
form.submit();