CMS Development

FurqanAli
Participant

How to redirect form based on select field which is made by using a selecting a form field.

SOLVE

Hi there,

Can someone help me with how I can redirect a form to different thank you pages based on select field values? Also, I have a custom module with a form selection option through a form field in my module.

Thanks for the great help as always.

0 Upvotes
1 Accepted solution
piersg
Solution
Key Advisor

How to redirect form based on select field which is made by using a selecting a form field.

SOLVE

You can do this

let result;
window.addEventListener('message', event => {
  if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
    result = event.data.data.find(x => x.name === 'name_of_your_select_field').value;
  }
  if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
    if (result === 'foo') {
      window.location = 'https://www.example1.com';
    } else if (result === 'bar'){
      window.location = 'https://www.example2.com';
    }
  }
});

 

View solution in original post

0 Upvotes
2 Replies 2
piersg
Solution
Key Advisor

How to redirect form based on select field which is made by using a selecting a form field.

SOLVE

You can do this

let result;
window.addEventListener('message', event => {
  if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
    result = event.data.data.find(x => x.name === 'name_of_your_select_field').value;
  }
  if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
    if (result === 'foo') {
      window.location = 'https://www.example1.com';
    } else if (result === 'bar'){
      window.location = 'https://www.example2.com';
    }
  }
});

 

0 Upvotes
FurqanAli
Participant

How to redirect form based on select field which is made by using a selecting a form field.

SOLVE

Thanks a lot @piersg  I will definitely try this.

0 Upvotes