Webflow sync, pageviews & more.
NEW
Answers

How can I dynamically redirect to a CMS created after form submission in Webflow?

To dynamically redirect to a CMS page created after form submission in Webflow, you can follow these steps:

1. Create a form on your website using the Form element in Webflow. Make sure to set up the necessary form fields as per your requirements.

2. Add a Submit button to your form and give it a unique ID or class name for targeting it later.

3. After submitting the form, navigate to the Project Settings in Webflow. Under the Forms tab, identify the form you created and click on it.

4. In the Form Actions panel, click on Add an action and select Redirect to Page.

5. In the Redirect to Page settings, you can manually enter the URL of the CMS page you want to redirect to after form submission. However, since you want to dynamically redirect to a CMS page that is created after form submission, you'll need to add some custom code to achieve this.

6. Open the page where your form is placed in the Webflow Designer, and click on the Page Settings tab on the right sidebar.

7. Add a Custom Code Block to the Footer Code section.

8. In the Custom Code Block, you can add JavaScript code to handle the form submission and dynamic redirect. Below is an example of how you can achieve this:

```javascript

```

In the above code:

- Replace `'your-submit-button-id'` with the actual ID or class name of your form's submit button.
- Replace `'your-cms-collection'` with the actual slug of your CMS collection.
- Replace `'your-form-id'` with the actual ID or class name of your form.
- Replace `'/webflow-form-endpoint'` with the actual form endpoint URL. You can find this endpoint in the form's Action URL in Webflow's Form Settings.

9. Save your changes and publish your site for the code to take effect.

Now, when a user submits the form, the JavaScript code will make a request to the specified form endpoint. It will then receive a response, parse it (assuming it's JSON), and extract the slug field (or any other relevant information) from the response. Based on this data, it will construct the URL of the newly created CMS page and redirect the user to that page.

Note: This solution assumes you have some form of server-side logic to handle form submissions and create new CMS items programmatically. The code above is just an example to demonstrate the client-side part of the redirection process.

Rate this answer

Other Webflow Questions