Running a code script on form submission

  • 11 September 2020
  • 1 reply
  • 189 views

Badge

I am trying to use 3 different thank you pages based on the option selected in the dropdown.

I tried using the code form

But not getting the desired result. It occasionally works.

window.ub.hooks.afterFormSubmit.push(function() {
var valueNew = $( "#which_kind_of_selfdefense_videos_do_you_want_to_watch" ).val()
console.log(valueNew);

if(valueNew == "Reality-Based Self Defense"){
   console.log('case1');
   window.history.pushState('', 'New Page Title', 'https://try.ukfightlab.tv/reality-based/'); 
}
if(valueNew == "Pressure-Points Based Self-Defense"){
   console.log('case2');
 window.history.pushState('', 'New Page Title', 'https://try.ukfightlab.tv/pressure-point/'); 
}
if(valueNew == "Chinese/Mystical Self-Defense"){
   console.log('case3');
   window.history.pushState('', 'New Page Title', 'https://try.ukfightlab.tv/pressure-point/');
}
});

1 reply

Badge +1

@Zaid_Nazir there is an easier and simpler way “sil vous plait” ;).
Rather than using the hooks, you can create an intermediate page and redirect your form submission to this page. On the intermediate page, you can capture form data and use redirect scripts based on the response. If you need captured data on the final thank you page - you can add that into your redirect script too. The only downside is you will be using 1 extra page but it’ll be much simpler. Hope this helps.

Reply