I am using contact form 7 on this page: https://www.thenetwork360group.com/cilt-exam-series/. I am trying to redirect the user based on what exam they enrol on at the end.
I realise having this many if / else statements in one function is messy. I have tried multiple things, I tried switch statements but the form did not redirect after sending.
This is currently what I have:
document.addEventListener( 'wpcf7submit', function( event ) {
if ( '5686' == event.detail.contactFormId ) {
var lt2 = document.getElementById("_lt2").value;
var lt3 = document.getElementById("_lt3").value;
var lt5 = document.getElementById("_lt5").value;
var om3 = document.getElementById("_om3").value;
var om5 = document.getElementById("_om5").value;
if (lt2 == "1 - £44") {
location = 'https://www.thenetwork360group.com/cart/?add-to-cart=5683';
} else if (lt2 == "2 - £88") {
location = 'https://www.thenetwork360group.com/cart/?add-to-cart=5684';
} else if (lt2 == "3 - £132") {
location = 'https://www.thenetwork360group.com/cart/?add-to-cart=5682';
} else if (lt3 == "1 - £72") {
location = 'https://www.thenetwork360group.com/cart/?add-to-cart=5707';
} else if (lt3 == "2 - £144") {
location = 'https://www.thenetwork360group.com/cart/?add-to-cart=5708';
} else if (lt5 == "1 - £74") {
location = 'https://www.thenetwork360group.com/cart/?add-to-cart=5709';
} else if (lt5 == "2 - £148") {
location = 'https://www.thenetwork360group.com/cart/?add-to-cart=5710';
} else if (lt5 == "3 - £222") {
location = 'https://www.thenetwork360group.com/cart/?add-to-cart=5711';
} else if (om3 == "1 - £72") {
location = 'https://www.thenetwork360group.com/cart/?add-to-cart=5712';
} else if (om5 == "1 - £74") {
location = 'https://www.thenetwork360group.com/cart/?add-to-cart=5713';
} else if (om5 == "2 - £148") {
location = 'https://www.thenetwork360group.com/cart/?add-to-cart=5714';
} else if (om5 == "3 - £222") {
location = 'https://www.thenetwork360group.com/cart/?add-to-cart=5715';
}
}
}, false )
The ID's related to the form, so var lt2 related to the following ID:
[select lt2 id:_lt2 "1 - £44" "2 - £88" "3 - £132"]
I am expeting the user to be redirected based on which option they have selected, above. However, it only seems to be redirecting to the first option.
Any advice would be great.