Redirecting Hubspot form to different urls depending on property selected.
SOLVE
Hi all, I've been crawling through forums to try to redirect a Hubspot form to a url based on the 'country_region' property selected, however my own attempts at embedding the code on our wordpress site have failed. Could anyone please review what I have below and let me know if there is something I've missed?I have 2 potential hypothesis as to where I'm going wrong:
The form was originally set up to redirect to a thank you page and every time I test this it still redirects me back to the original thank you page or thank you message - I'm not sure if it is possible to override this.
Appreciate any guidance this community can provide.
The code here runs on your page but the form is on an iFrame. To reference the form fields you have to use the passed in jQueryFrom argument which contacts the data from the iframe about the submitted form.
Redirecting Hubspot form to different urls depending on property selected.
SOLVE
Thanks Lee, I removed that and the error message from the Console (regarding onFormSubmit) has disappeared, however the form still redirects to the thank you message no matter what country I select. The latest version of the embedded code is:
Sep 15, 20228:30 AM - edited Sep 15, 20228:31 AM
HubSpot Employee
Redirecting Hubspot form to different urls depending on property selected.
SOLVE
Are you seeing the "form is submitted already" in the browser console? What errors are you seeing in your browser console? I embedded your code on a test page of mine and it redirected to google just fine.
Redirecting Hubspot form to different urls depending on property selected.
SOLVE
Hi Lee,
I am seeing the following 2 errors in the broswer console after I submit the form:
v2.js:1 There was an error when running your onFormSubmit function from hbspt.forms.create runCustomerCallbackFunction @ v2.js:1
v2.js:1 TypeError: $ is not a function at onFormSubmit ((index):311:31) at Object.runCustomerCallbackFunction (v2.js:1:422851) at t.submitForm (v2.js:1:540228) at v2.js:1:538744 at l (v2.js:1:152736) at v2.js:1:153401 at Array.u (v2.js:1:156860) at o (v2.js:1:152109)
I tried in incognito again and still had the same result. Hopeful to hear that the redirect worked on your page but not sure what's going wrong on my site.
Appreciate any other insights you may have into the error codes.
Redirecting Hubspot form to different urls depending on property selected.
SOLVE
Thank you so much - that got it working in the sense that now it redirects to google after I submit the form instead of the thank you page, however I'm still having the issue where it won't redirect to yahoo based on the selected country being United Kingdom - can I please ask you for further assistance with this?
I have tried switching out "United Kingdom" for other countries to see if the space was causing the issue but it is still not redirecting - all form submissions now go through to Google only.
Redirecting Hubspot form to different urls depending on property selected.
SOLVE
I'm sorry I don't understand the question - I input the console log before and after submitting the form and got the same error message each time - the only difference was the VM numbers (e.g. the message was
VM1494:1 Uncaught ReferenceError: selectedCountry is not defined at <anonymous>:1:13 (anonymous) @ VM1494:1 after I had submitted the form).
var ukLink = "https://www.yahoo.com/"; var europeLink = "https://www.google.com/"; var selectedCountry = jQuery('select[name="country_region"]').val(); var selectedCountry = jQuery('input[name="country_region"]').val(); console.log(selectedCountry)
However I still got the same error message when I searched for console.log(selectedCountry) in the Console: VM497:1 Uncaught ReferenceError: selectedCountry is not defined at <anonymous>:1:13
Sep 15, 202211:21 AM - edited Sep 15, 202212:04 PM
Member
Redirecting Hubspot form to different urls depending on property selected.
SOLVE
Thanks, I tried that, so the latest version of the code is below - however it still did not redirect and is showing the same error message when I searched for console.log(selectedCountry) in the Console.
var ukLink = "https://www.yahoo.com/"; var europeLink = "https://www.google.com/"; var selectedCountry = jQuery('select[name="country_region"]').value; console.log(selectedCountry)
Sep 15, 202211:27 AM - edited Sep 15, 202211:29 AM
HubSpot Employee
Redirecting Hubspot form to different urls depending on property selected.
SOLVE
I used your exact code and it redirected to the eurpoe page when Ireland was selected. There is nothing wrong with the code you've provided. There must be something wrong with your jQuery implementation or something.
Until you can get jQuery to assign the value to selectedCountry, I think you'll have issues. Try using vanilla JS.
Redirecting Hubspot form to different urls depending on property selected.
SOLVE
Hi Lee,
The issue that I am having now is that it redirects to the europe page no matter what country is selected, would you please try to submit the form using the country 'United Kingdom'?
I'll look into the other options you suggested in the meantime.
The code here runs on your page but the form is on an iFrame. To reference the form fields you have to use the passed in jQueryFrom argument which contacts the data from the iframe about the submitted form.
Redirecting Hubspot form to different urls depending on property selected.
SOLVE
Hi Lee,
Thanks for your reply. I have not been able to remove the redirect from the form - it won't let me save it without either having a thank you message or redirect. Can I ask how you saved a form without a redirect or thank you message?
Right now I have it set to 'thank you message', but I've not had success with either 'thank you message' or redirect.