# Form Target URL Driven by Wordpress Custom Field

**URL:** <https://community.hubspot.com/t/form-target-url-driven-by-wordpress-custom-field/66065>\
**Category:** APIs & Integrations\
**Created:** [September 28, 2022, 2:39pm UTC](https://community.hubspot.com/t/form-target-url-driven-by-wordpress-custom-field/66065 "2022-09-28T14:39:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SClick](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@SClick](https://community.hubspot.com/u/SClick)\
**Post date:** [September 28, 2022, 2:39pm UTC](https://community.hubspot.com/t/form-target-url-driven-by-wordpress-custom-field/66065/1 "2022-09-28T14:39:19Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [September 29, 2022, 8:31pm UTC](https://community.hubspot.com/t/form-target-url-driven-by-wordpress-custom-field/66065/2 "2022-09-29T20:31:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SClick](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@SClick](https://community.hubspot.com/u/SClick)\
**Post date:** [September 29, 2022, 8:43pm UTC](https://community.hubspot.com/t/form-target-url-driven-by-wordpress-custom-field/66065/3 "2022-09-29T20:43:04Z")

</div>

We’ve actually got this working!  
\<script charset=“utf-8” type=“text/javascript” src=“[//js.hsforms.net/forms/v2-legacy.js](https://js.hsforms.net/forms/v2-legacy.js)”\>\</script\>  
\<![endif]--\>  
\<script charset=“utf-8” type=“text/javascript” src=“[//js.hsforms.net/forms/v2.js](https://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\>

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [September 29, 2022, 8:49pm UTC](https://community.hubspot.com/t/form-target-url-driven-by-wordpress-custom-field/66065/4 "2022-09-29T20:49:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SClick](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@SClick](https://community.hubspot.com/u/SClick)\
**Post date:** [September 29, 2022, 9:00pm UTC](https://community.hubspot.com/t/form-target-url-driven-by-wordpress-custom-field/66065/5 "2022-09-29T21:00:37Z")

</div>

Ah yes amazing thank you for your help!

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [September 29, 2022, 8:38pm UTC](https://community.hubspot.com/t/form-target-url-driven-by-wordpress-custom-field/66065/6 "2022-09-29T20:38:52Z")

</div>

Hi @SClick,

you can modify the embed code with the “onFormSubmitted” option from the [advanced form options](https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options).

default embed code:

```lia-code-sample
<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:

```lia-code-sample
<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
