APIs & Integrations

SClick
Member

Form Target URL Driven by Wordpress Custom Field

SOLVE

Hi!
We're looking for a way for our client to add their preferred target URL into a custom field on a post, which then defines the redirect of the form (using Hubspot embed as the client prefers this to using something like Gravity etc). 

 

Any help appreciated!

0 Upvotes
1 Accepted solution
Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Form Target URL Driven by Wordpress Custom Field

SOLVE

Hi @SClick

 

you can modify the embed code with the "onFormSubmitted" option from the advanced form options.

 

default embed code:

 

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
  hbspt.forms.create({
    region: "na1",
    portalId: "xxxxxxx",
    formId: "xxxxxxxxxx",
    version: "V2_PRERELEASE"
  });
</script>

 

 

modified embed code:

 

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
  hbspt.forms.create({
    region: "na1",
    portalId: "xxxxxxx",
    formId: "xxxxxxxxxx",
    version: "V2_PRERELEASE",
    onFormSubmitted: "https://yourredirect.com"
  });
</script>

 

 

 

hope this helps

 

 

best, 

Anton

 

Anton Bujanowski Signature

View solution in original post

5 Replies 5
Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Form Target URL Driven by Wordpress Custom Field

SOLVE

Hi @SClick

 

you can modify the embed code with the "onFormSubmitted" option from the advanced form options.

 

default embed code:

 

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
  hbspt.forms.create({
    region: "na1",
    portalId: "xxxxxxx",
    formId: "xxxxxxxxxx",
    version: "V2_PRERELEASE"
  });
</script>

 

 

modified embed code:

 

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
  hbspt.forms.create({
    region: "na1",
    portalId: "xxxxxxx",
    formId: "xxxxxxxxxx",
    version: "V2_PRERELEASE",
    onFormSubmitted: "https://yourredirect.com"
  });
</script>

 

 

 

hope this helps

 

 

best, 

Anton

 

Anton Bujanowski Signature
Jaycee_Lewis
Community Manager
Community Manager

Form Target URL Driven by Wordpress Custom Field

SOLVE

Hi, @SClick 👋 Thanks for the question. Hey, @Anton @louischausse, have you tacked anything similar? Thank you for taking a look! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes
SClick
Member

Form Target URL Driven by Wordpress Custom Field

SOLVE

We've actually got this working!

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script>
<![endif]-->
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
hbspt.forms.create({
portalId: "xxxxxxx",
formId: "xxxxxxxx-xxxx-xxxxxxxx-xxxxxxxxx",
inlineMessage: 'Success',
onFormSubmit: function($form){
setTimeout( function() {
var formData = $form.serialize();
window.location = "[acf field="target_url"]"
}, 250 ); // Redirects to url from advancved custom fields after 250 milliseconds.
}
});
</script>

Anton
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Form Target URL Driven by Wordpress Custom Field

SOLVE

Awesome!

just one recommendation: Change "onFormSubmit" to "onFormSubmitted" since this will trigger the redirect after the form is submitted. When you're working with "onFormSubmit" submissions can get lost/not be submitted and the user/visitor is just redirected

 

 

best, 

Anton

Anton Bujanowski Signature
SClick
Member

Form Target URL Driven by Wordpress Custom Field

SOLVE

Ah yes amazing thank you for your help!