Can you pass hidden field values as url parameters on a webflow form button link?

Published on
September 22, 2023

Yes, you can pass hidden field values as URL parameters on a Webflow form button link by utilizing JavaScript and the Webflow.js library.

Here's a step-by-step guide on how to achieve this:

  1. Add a hidden field to your Webflow form. To do this, go to the Form Block settings, select the form you want to add the hidden field to, and click the "Add Field" button. Choose the "Hidden" field type and provide a name for the field.

  2. Assign a value to the hidden field using JavaScript. For example, you can use the following code snippet:

document.getElementById("hidden-field-name").value = "hidden-field-value";

Replace "hidden-field-name" with the actual name of your hidden field and "hidden-field-value" with the value you want to pass as a URL parameter.

  1. Add a custom attribute to your form button link to capture the hidden field value. In Webflow, select the button element and go to the "Attributes" panel on the right-hand side. Click the "+" button to add a custom attribute and provide a name for the attribute (e.g., "data-hidden-field-value"). Set the value of the attribute to the value of the hidden field, like this:
data-hidden-field-value="{{formName.fieldName}}"

Replace "formName" with the name of your form and "fieldName" with the name of your hidden field.

  1. Update the link URL to include the URL parameter. In the link URL of your form button, include the URL parameter and reference the custom attribute value. For example:
www.example.com?param={{button.getAttribute('data-hidden-field-value')}}

Replace "www.example.com" with your desired URL and "param" with the name of the URL parameter you want to use.

When the form button is clicked, the hidden field value will be captured and appended as a URL parameter to the link URL. This allows you to pass the hidden field value as a parameter and retrieve it on the destination page.

Example:

Let's say you have a hidden field with the name "email" and you want to pass its value as a URL parameter to a form button link. You can follow these steps:

  1. Add a hidden field in the form with the name "email".
  2. Use JavaScript to assign a value to the hidden field. For instance:
document.getElementById("email").value = "test@example.com";
  1. Add a custom attribute to the form button link with the name "data-email" and the value "{{formName.email}}".
  2. Update the link URL to include the URL parameter. For example:
www.example.com?email={{button.getAttribute('data-email')}}

When the form button is clicked, the value "test@example.com" will be passed as the "email" URL parameter, and the URL will become "www.example.com?email=test@example.com".

By following these steps, you can successfully pass hidden field values as URL parameters on a Webflow form button link.

Additional Questions:

  1. How do I add a hidden field to a Webflow form?
  2. Can I use JavaScript in Webflow to manipulate form data?
  3. How do I add custom attributes to elements in Webflow?