URL redirect with parameters
<script>
function sendParameters(wid, labelsArray, parametersArray) {
//select form by wid
var $form = $('form[data-wid="' + wid + '"]');
//get the fields's values and store them in an array
var encodedValsArray = labelsArray.map(function(e, i) {
return $form.find('input[name="' + base64_encode(e) + '"]').val();
}).map(function(e, i) {
return encodeURIComponent(e);
});
//build query string
var queryString = encodedValsArray.reduce(function(str, val, i) {
if (i === 0) {
return str + parametersArray[i] + '=' + val;
} else {
return str + '&' + parametersArray[i] + '=' + val;
}
}, '?');
console.log(queryString);
//get the redirect url
var redirectUrl = $form.find('input[name="redirect"]').val();
//amend redirect url in form by adding fields from form
$form.find('input[name="redirect"]').val(redirectUrl + queryString);
}
window.instapageFormSubmitSuccess = function(form, wid) {
if (wid === 268) {
sendParameters(wid, ['First Name', 'Last Name', 'Email', 'Phone Number'], ['first', 'last', 'email', 'phone']);
} else if (wid === 195) {
sendParameters(wid, ['Email'], ['email']);
}
}
</script>
<script>
window.instapageFormSubmitSuccess = function(form) {
//define the fields' labels
var labelsArray = ['First Name', 'Last Name', 'Email'];
//get the fields's values and store them in an array
var encodedValsArray = labelsArray.map(function(e, i) {
return $(form).find('input[name="' + base64_encode(e) + '"]').val();
}).map(function(e, i) {
return encodeURIComponent(e);
});
//get the redirect url
var redirect_url = ijQuery(form).find('input[name="redirect"]').val();
// Amend redirect url in form by adding fields from form
ijQuery(form).find('input[name="redirect"]').val(redirect_url + '?name=' + encodedValsArray[0] + '%20' + encodedValsArray[1] + '&email=' + encodedValsArray[2]);
}
</script>
window.instapageFormSubmitSuccess = function( form )
{
// get values from form fields
var search_string = ijQuery( form ).find( 'input[name="'+ base64_encode( 'replace with form field label' ) +'"]').val();
var email = ijQuery( form ).find( 'input[name="'+ base64_encode( 'Email' ) +'"]').val();
// Get the actual redirect url
var redirect_url = ijQuery( form ).find( 'input[name="redirect"]' ).val();
// Amend redirect url in form by adding fields from form
ijQuery( form ).find( 'input[name="redirect"]' ).val( redirect_url + '?query='+ search_string + '&email='+ email );
}