The previous method involved a script to insert the URL parameters as the page loaded. The new solution removes the need for the custom script.
A Quick Review
Pre-populating forms allows form owners to insert text or select answers on a form. Some reasons for doing this include:
- Letting form users repeat a previously-submitted result (“Register another person”, for example)
- Creating a simple approval process
- Populating Hidden Field items with connected object ID values in Salesforce
- Making a voting form or survey using emailed links
The form’s Pre-populate link includes parameters in the URL to prefill form items. Embedded forms do not use the direct link to the form but instead uses the embed code with a custom prePopulate parameter.
Before now, form owners needed to find a way to get custom values into that prePopulate parameter using on-page scripts or back-end code. This update removes that need and offers an easier method.
Pre-populate Embedded Forms
Step 1: Build the form and insert the Embed Code
Once the form is complete and ready to embed, go to the Share -> Embed Code page and copy the embed code in its entirety. Paste the code into the web page where it should appear. For help with using the embed code, see an earlier article for tips.
Step 2: Add the prePopulate parameter
The prePopulate parameter inserts values into the form as it loads. To use URL parameters to pre-populate the embedded form, add the value ‘window.location’ to the embed code prePopulate parameter:
<a name="form491144067" id="formAnchor491144067"></a>
Step 3: Customize the URL
The URL format is the same as the regular Pre-populate link. Locate the form’s Pre-populate link on the Share page, then use the part of the link from the question mark to the end in your page URL. For example, if the form is on the page named ‘contact.html’ the URL may look like:
To Pre-populate the embedded form on that page, add the Pre-populate link segment:
The embedded form displays the pre-populated values.