Using field value from one form in another form using Contact Form 7 in JQuery/Javascript

  contact-form-7, forms, javascript, jquery, wordpress

This is my first question on Stack Overflow. I appreciate your patience.

I have two forms using Contact Form 7, the first form navigates to the second form using the WordPress plugin ‘Contact Form 7 Multi-Step Forms’.

When the Submit is pressed on the second form I want to use the field values in both forms to send in a PayPal URL.

The problem I am getting is obtaining the field values from the first form when submitting the second form. In this case I want to use the variable ‘finalamount’ which is obtained from a field value from the first form and use use it in the PayPal URL when submitting the second form. If anyone can help please.

 <script>

// First Form
document.addEventListener( 'wpcf7mailsent', function( event ) {

if ( '627' == event.detail.contactFormId ) {
var inputs = event.detail.inputs;

for ( var i = 0; i < inputs.length; i++ ) {
if ( 'amount-one' == inputs[i].name ) {finalamount = parseInt((inputs[i].value));}
}
}

// Second Form
if ( '1241' == event.detail.contactFormId ) {
var inputs = event.detail.inputs;

for ( var i = 0; i < inputs.length; i++ ) {
if ( 'currencytype' == inputs[i].name ) {finalcurrencytype = (inputs[i].value); }
}
}

window.location.href = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&[email protected]&amount=" + finalamount;

}, false );

</script>

Source: Ask Javascript Questions

LEAVE A COMMENT