Easily build and embed forms on your site. Try HubSpot Forms for free.
Forms

How do I auto-populate form fields using a query string?

Last updated: April 26, 2018

free

You can add query strings to the URL of one of your landing pages to auto-populate field values in the form on the page. This works for the following field types: single-line text, multi-line text, dropdown select, multiple checkboxes, number, radio select, single checkbox, and date picker. This also works for hidden form fields.

Please note: it is not possible to use query strings to auto-populate dependent form fields.

Create query strings with set values

  • Navigate to your contacts.
  • Click the Customize dropdown menu and select Edit properties
  • Click the name of the property for which you'd like to pre-populate values in your form. 
  • Copy the internal name of the property to use in your query string. 

refresh-property-internal-name

  • Create your URL:
    • Add a question mark to the end of the URL of the landing page that contains the form.  
    • Add the internal name of the property, followed by an equal sign and the desired value, which will be auto-populated in the field. There are some rules for adding values, depending on the field type of the property:
      • Single checkbox query strings must contain either a true or false value, not yes or no.
      • Date picker query strings must contain a date value in a YYYY-MM-DD format.
      • Multiple checkboxes values must match the property's value options exactly, with a semi-colon separating multiple values.
      • Radio select and dropdown select values must match the property's value options exactly.
    • Separate multiple properties with an ampersand.
The following is an example and a breakdown of a properly formatted URL with query strings:

http://www.domain.com/marketing-offer?firstname=John&lastname=Smith&email=jsmith@email.com
&favorite_season=Winter&favorite_natural_disasters=Blizzard;Hurricane&number_property=7&will_you_come_to_the_party=Maybe&do_you_like_parties=true&date_of_party=2018-10-24

  • Beginning of query string and single line text field: ?firstname=John
  • Single-line text field: &lastname=Smith
  • Single-line text field: &email=jsmith@email.com
  • Dropdown select field: &favorite_season=Winter
  • Multiple checkboxes field: &favorite_natural_disasters=Blizzard;Hurricane
  • Number field: &favorite_number=7
  • Radio select field: &will_you_come_to_the_party=Maybe
  • Single checkbox field: &do_you_like_parties=true
  • Date picker field: &date_of_party=2018-10-24

Create dynamic query strings with personalization tokens 

If you have a Marketing Hub BasicProfessional, or Enterprise account, you can also create personalized URLs that will auto-populate a form based on known contacts' information. Here's how this would work in a HubSpot email:

Please note: this will only function as intended if the link is going to HubSpot-hosted content with a HubSpot form and the link is placed on a HubSpot-hosted page (or HubSpot email) or an externally hosted page with the HubSpot tracking code.
  • Navigate to Content Email
  • Create a new email or hover over an existing email and click Edit.
  • First, you'll need to find the code for any personalization tokens you'd like to use in your URL. To do this, click the personalization token icon in the rich text toolbar. 

  • Select the personalization token you'd like to add to your URL. Continue to add additional personalization tokens as needed. 
  • The personalization tokens will now appear in the body of your email. Click the source code (<>) icon in the rich text toolbar to see the HTML of your email. 

  • In the source code, you'll see the raw code for each personalization token you've added the body of your email. Each one will be surrounded by double brackets . Highlight one of them (in this case, we want to use first name so the token code is {{contact.firstname}} ), then right click and select Copy. Click Cancel and close to exit the source code. 

  • Next, click the link to which you'd like to add your query string, then select Options.

  • Add a question mark at the end of the Link URL and the internal name of the property (see above), then an equal sign, then paste the personalization token code. Click Update link
personalization_token_query_string_2.gif

Repeat this as needed for any other personalization tokens you included in your body. Add an ampersand (&) between each query string.

To test your link, send yourself a test email as a particular contact.

New Call-to-action

Was this article helpful?

If you still need help you can get answers from the , or to contact support.