Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The example above shows a parameters for firstname and lastname in the URL.  Since you may want to allow the user to override the value once the a form displays, use a Custom Default Value rule on the component you want to load data into.  Access the Custom Default Value editor from the Data tab of a Component's settings.  A sample rule is provided below to insert the first name and last name provided in the URL into a single Text Component.

Code Block
languagejs
titleSet Text Component Value
linenumberstrue
var params = new URLSearchParams(window.location.hash.split('?')[1]);

if(params.get('firstname') && params.get('lastname'))
{
	value = params.get('firstname') + ' ' + params.get('lastname');
}

The snippet above can be repurposed for a variety of uses.  It's helpful to understand the basic mechanics of this code:

  • To set the values to a Component, you first need them accessible in the JavaScript.  Line 1 can be copied verbatim into any similar rule code and is used to extract the parameters from the URL.

  • Line 2 is making sure there is text provided in the elements you are working with. This may or may not be a necessary step depending on your use case.  You will need to understand a bit about control the display of text when your objects don't alway exist.  You can learn more about nulls, NaN, and undefined scenarios here.  

  • Line 4 assigns the firstname parameter and the lastname parameter to the Text component, and inserts a space between them.

To download a working example form of the scenario described, click here

  • Add firstname=John&lastname=Doe to the query parameters of the imported form's link to load the name into the Employee Name field.  If your link already has a question mark in it, do not add another one.  Append query parameters with the ampersand.

  • In the form designer, you can review or modify the rule by accessing the settings of the Employee Name Text Component.  Click the Data tab, and expand the Custom Default Value section.

Warning
titleIE 11 Warning

The method for accessing parameters in the URL described here is not supported in IE11. If forms users are browsing IE11, you will need to use an alternate method to get the data from the URL and parse it manually.