# Creating a dynamic url based on properties from a form

**URL:** <https://community.hubspot.com/t/creating-a-dynamic-url-based-on-properties-from-a-form/44679>\
**Category:** APIs & Integrations\
**Tags:** forms, contacts\
**Created:** [October 1, 2021, 11:57am UTC](https://community.hubspot.com/t/creating-a-dynamic-url-based-on-properties-from-a-form/44679 "2021-10-01T11:57:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jelmert](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jelmert/32/82797_2.png) [@Jelmert](https://community.hubspot.com/u/Jelmert)\
**Post date:** [October 1, 2021, 11:57am UTC](https://community.hubspot.com/t/creating-a-dynamic-url-based-on-properties-from-a-form/44679/1 "2021-10-01T11:57:33Z")

</div>

Hi,

Hope this is the right place for this question.

I want to create a dynamic url from properties from a form; like firstname, lastname and email.

I can do it with an email like this link: [Create a Dynamic URL using Hubspot CRM - Growthrobotics](https://siteauditor.com/create-a-dynamic-url-using-hubspot-crm/)

But not from a form.. it does not read the properties or something.. We use something like this:

[https://company.com/SelfRegister/fn={{contact.firstname}}&ln={{contact.lastname}}&em={{contact.email}}&Revisit=True](https://using.hrorganizer.com/SelfRegister/Index/4e15976e-7d27-4b1e-a30a-2e3f62d1e68b?fn=%7B%7Bcontact.firstname%7D%7D&ln=%7B%7Bcontact.lastname%7D%7D&em=%7B%7Bcontact.email%7D%7D&Revisit=True)

But it does not save the contact firstname, lastname and email…

The link goes to a external site where the visitor can do a test and the result is sent to them to the email adres they fill in in the form.

Can anyone help? hope i made the question clear enouh

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [October 1, 2021, 12:55pm UTC](https://community.hubspot.com/t/creating-a-dynamic-url-based-on-properties-from-a-form/44679/2 "2021-10-01T12:55:13Z")

</div>

Hi @Jelmert ,

Do you want to redirect the user to the external site as soon as the user submits the form?  
If that is the case, you need to customize the [form embed code](https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options). Use the onFormSubmitted callback to generate your URL using JavaScript or jQuery.

Your code could look something like this:

```lia-code-sample
hbspt.forms.create({
 portalId: '',
 formId: '',
 onFormSubmitted: function ($form) {
 window.location.href = `https://company.com/SelfRegister/fn=${$('input[name="firstname"]').val()}&ln=${$('input[name="lastname"]').val()}`
 }
});

```

---

<div class="post-metadata">

**Author:** ![Jelmert](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jelmert/32/82797_2.png) [@Jelmert](https://community.hubspot.com/u/Jelmert)\
**Post date:** [October 4, 2021, 8:08am UTC](https://community.hubspot.com/t/creating-a-dynamic-url-based-on-properties-from-a-form/44679/3 "2021-10-04T08:08:10Z")

</div>

Hi @Teun ,

Thanks for this! We will try this.

We do want to redirect them as soon as they fill in the form. Think this could work.

---

<div class="post-metadata">

**Author:** ![Jelmert](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jelmert/32/82797_2.png) [@Jelmert](https://community.hubspot.com/u/Jelmert)\
**Post date:** [October 5, 2021, 9:37am UTC](https://community.hubspot.com/t/creating-a-dynamic-url-based-on-properties-from-a-form/44679/4 "2021-10-05T09:37:11Z")

</div>

Hi @Teun

Could you please explain where we should edit the form embed code? The link only shows how to edit it.

Do we need to create a custom form module? Or can we edit the embed code in the formsmenu?

(The form will be located on a hubspotpage and linked to an external webpage)

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [October 5, 2021, 5:41pm UTC](https://community.hubspot.com/t/creating-a-dynamic-url-based-on-properties-from-a-form/44679/5 "2021-10-05T17:41:12Z")

</div>

Hi @Jelmert ,

Create a custom module, it should at least have a [‘form’ field](https://developers.hubspot.com/en/docs/cms/building-blocks/module-theme-fields#form). Your code could look something like this:

```lia-code-sample
<div class="c-form" id="js-form-module" data-portal_id="{{hub_id}}"
 data-form_id="{{module.form.form_id}}">
 <script>
 var container = document.getElementById('js-form-module');

 if (container) {
 var portalId = container.dataset.portal_id;
 var formId = container.dataset.form_id;

 hbspt.forms.create({
 portalId: portalId,
 formId: formId,
 cssRequired: '',
 onFormSubmitted: function ($form) {
 window.location.href = `https://company.com/SelfRegister/fn=${$('input[name="firstname"]').val()}&ln=${$('input[name="lastname"]').val()}`
 } 
 });
 }
 </script>
 </div>

```
