- Before you start: requirements and limitations
- Step 1: Set the form to redirect to an outside URL
- Step 2: Add the code to the page’s JavaScript settings
- Step 3: Replace the field names and parameter names in the code
How to use the passed parameters on the destination page
- Getting help with custom code
You can send the information that visitors enter in an Instapage form, such as their name, email address or/and company, to the page they are redirected to after they submit the form. The form values are added to the redirect URL as URL parameters (also called query string parameters or query parameters), for example https://example.com/thank-you?name=John&email=john%40example.com.
This article is for Instapage users who redirect a form to another page, such as a thank-you page, a checkout page, or a second form, and want that page to use the visitor’s answers, for example, to greet the visitor by name or to prefill a field. The method uses a JavaScript snippet that you add to your landing page’s settings.
This article covers sending form submission values (what the visitor types into the form) through the URL. To pass the URL parameters that are already in your landing page’s URL (for example, UTM parameters from an ad) to the redirect page, you don’t need code: use the native Pass URL parameters toggle described in Send parameters through the URL upon redirect.
Before you start: requirements and limitations
The form must redirect to an outside URL after submission (Step 1). The code doesn’t work with the Instapage page redirect option, even if the destination is an Instapage page.
The code sends values from single-line input fields, such as Name, Email, Company or Phone. The code doesn’t send values from Text Area (multi-line text), Radio Button, Checkbox or Dropdown fields. For the field types, see The different types of form fields.
A page can have only one
instapageFormSubmitSuccessfunction. If your page already uses a form submit callback (for example, for a tracking pixel), put all the code into the same function (see the note in Step 2).To show the passed values on the destination page with Dynamic Text Replacement, your plan must include Dynamic Text Replacement (see How to use the passed parameters on the destination page).
Step 1: Set the form to redirect to an outside URL
In the Instapage editor, click the form, then click Edit Form in the menu on the right. The form editor opens (see The Form Builder and Form Library).
On the right, open Form Submissions and stay on the REDIRECT tab.
Under Destination, click OUTSIDE URL.
In the URL field, enter the full address of the page that visitors should go to after they submit the form, then click SAVE.
Click Update in the top-right corner of the form editor, close the form editor, then save and update your page.
The screenshot below shows the Form Submissions panel with the REDIRECT and DOWNLOAD tabs, the Destination options INSTAPAGE and OUTSIDE URL (with OUTSIDE URL selected), an empty URL field with CANCEL and SAVE buttons, and the Thank You Message settings below.
The redirect must be set as an outside URL for the code to work, even if the destination page is an Instapage page. In that case, enter the destination page’s live URL. For more about redirect options, see How do I redirect to another page after form submission?
Step 2: Add the code to the page’s JavaScript settings
In the Instapage editor, open Settings and go to Javascript (see Using Custom HTML, Javascript and CSS on Your Page).
Paste the code below in the Footer section.
Replace the field names and parameter names as described in Step 3, then save and update your page.
<!-- Begin "Send parameters through the URL" || Help center -->
<!-- Insert in Settings->Javascript->Footer -->
<!-- CS:20230114-07-0 -->
<script>
window.instapageFormSubmitSuccess = function (form) {
// Get values from form fields
var param1 = encodeURIComponent(form.querySelector('input[name="' + 'Name' + '"]').value);
var param2 = encodeURIComponent(form.querySelector('input[name="' + 'Email' + '"]').value);
var param3 = encodeURIComponent(form.querySelector('input[name="' + 'Company' + '"]').value);
// Get the actual redirect url
var redirect_url = form.querySelector('input[name="redirect"]').value;
// Amend redirect url in form by adding fields from form
if (redirect_url.includes('?')) {
form.querySelector('input[name="redirect"]').value = redirect_url + '&name=' + param1 + '&email=' + param2 + '&company=' + param3;
} else {
form.querySelector('input[name="redirect"]').value = redirect_url + '?name=' + param1 + '&email=' + param2 + '&company=' + param3;
}
};
</script>
<!-- End "Send parameters through the URL" || Help center -->The instapageFormSubmitSuccess function can be present on the page only once, regardless of how many forms you have or how many actions you want to trigger after form submission. If you have several snippets that need to run after form submission, add all of them inside the same form submit callback function. If the snippets are in separate functions, only the last function in the page source code runs.
Step 3: Replace the field names and parameter names in the code
The code reads three form fields and adds three parameters to the redirect URL. Edit the highlighted values to match your own form:
| Text in the code | What it is | Replace it with |
|---|---|---|
'Name', 'Email', 'Company' (in the three var param lines) |
The names of the form fields the code reads | The names of your own form fields, written exactly as in your form, including capital letters and spaces |
name=, email=, company= (in both redirect_url lines) |
The names of the parameters added to the redirect URL | The parameter names you want in the URL. The parameter names don’t have to match the field names. Change them in both lines: one is used when the redirect URL already contains a question mark (?), the other when it doesn’t. |
To send more or fewer fields, add or remove a var param line and the matching '¶meter=' + param part in both redirect_url lines. For example, to also send a field named Phone, add var param4 = encodeURIComponent(form.querySelector('input[name="' + 'Phone' + '"]').value); and add + '&phone=' + param4 at the end of both lines.
Example: the form redirects to https://example.com/thank-you, and a visitor enters John Doe, john@example.com and Acme. After submission, the visitor is redirected to https://example.com/thank-you?name=John%20Doe&email=john%40example.com&company=Acme. The code encodes special characters, so a space becomes %20 and the @ sign becomes %40.
To also pass the parameters that are already in your landing page’s URL (for example, UTM parameters), not only the form values, turn on the Pass URL parameters toggle in the form’s redirect settings, as shown in Send parameters through the URL upon redirect.
Form values such as names and email addresses are personal data. Values in a URL can be saved in browser history, server logs and analytics tools, so send only the fields the destination page needs, and check that this complies with your privacy policy and with regulations such as GDPR.
How to use the passed parameters on the destination page
If the destination page is an Instapage landing page, the most common use of the passed parameters is to display them on the page or to store them with a new lead. Instapage does both with Dynamic Text Replacement (DTR): you type the parameter name between square brackets, and the published page replaces it with the parameter’s value from the URL. For the full guide, see Dynamic Text Replacement / How to use URL parameters on your page.
Dynamic Text Replacement is available only on some Instapage plans. To check which plans include it, see instapage.com/plans.
Show URL parameter values as text on the page
Type the parameter name between square brackets in any text element on the destination page.
Example:
The parameters in the URL are
?firstname=John&lastname=Doe.In the page editor, you type: “Welcome [firstname] [lastname]! We can provide the best solution for the [lastname] family.”
The live page displays: “Welcome John Doe! We can provide the best solution for the Doe family.”
The GIF below shows a published page with the text “Welcome, [animal] lovers! Thank you for coming from [utm_source].” When parameters for animal and utm_source are added to the page URL in the browser’s address bar and the page reloads, the placeholders are replaced with the parameter values.
Capture URL parameter values in a hidden form field
To save a parameter value with each lead, add a hidden field to the form on the destination page (see How do I use hidden fields?):
Click the form, click Edit Form, and select the field (or add a new single-line text field).
In the field settings on the right, enter a Label, for example, Source.
Under State, click HIDDEN.
Under Input, click POPULATED.
In Input value, type the parameter name between square brackets, for example
[utm_source].
Example:
The parameters in the URL are
?firstname=John&lastname=Doe.You create a hidden field with the label Name and the input value
[firstname] [lastname].When the visitor submits the form, the value “John Doe” is saved in the hidden field Name in your leads.
You can use one parameter per hidden field (as in the screenshot below) or combine several parameters in the same field (as in this example), depending on how you use the data.
The screenshot below shows the form editor with a hidden field labeled Source (Hidden) that contains [utm_source]. On the right, the field settings show the Label Source, the State set to HIDDEN, the Input set to POPULATED, and the Input value [utm_source].
Getting help with custom code
If you need help with custom functionality or code customization that the Help Center articles don’t cover, the Instapage Professional Services team can help customers on the Convert plan. The Convert plan includes Professional Services as well as additional features and services, listed on instapage.com/convert-benefits and in Convert Plan - Exclusive Benefits.