Tassos Marinos Tassos Marinos Joomla Extensions

How to Redirect User to a URL After Form Submission

Published in Convert Forms
Updated 02 Jan, 2024

One question we're frequently asked is how to redirect users to a URL or website after they've successfully submitted a form. By using Convert Forms, it's a very simple process.

In this article, we'll also share how to conditionally send visitors to a different page depending on the options they select in your form. You can send them to the promotion landing page that best suits their interests.

Enable Form Redirection

First, you'll need to have Convert Forms installed and create a form. You'll also need to have created the redirect page or know the URL to which you want to redirect users.

Open your form and click on the Submissions panel from the left. Next, select Redirect User from the 'Successful Submission Action' dropdown and set the URL you'd like to send the visitor to in the 'Redirect URL' option that appears below.

convert forms redirect user

Finally, you are given an option also to send the form data to the Redirect URL. If you Enable this option, then the form data will be available as appended GET parameters.

Redirecting to a new tab

All redirects occur in the same window (tab) by default. To do a redirection in a new tab, you will need to use the following Javascript snippet:

document.addEventListener('DOMContentLoaded', () => {
    var form = document.querySelector("#cf_XXX");
    form.addEventListener('beforeRedirectUser', function(e) {
        e.detail.target = '_blank';
    });
})

The code must be placed into the Custom Code option in the Design -> Advanced panel and wrapped with the <script> tags. Do not forget to replace "XXX" with the ID of your form.

Conditional Redirects Based On Form Fields

With Convert Forms, you can also redirect users to different pages or URLs, depending on what information they select and submit within the form.

First, follow the steps described in the Enable Form Redirection section and set a default redirection URL.

Next, edit and place the following PHP snippet into the PHP Scripts -> After Form Submission option.

// Get the value of the field you'd like to check
$value = $submission->params['YourTextFieldName'];

// Redirection option 1
if ($value == 'YOUR_VALUE_1')
{
    $submission->form->successurl = 'https://site.com/page1';
}

// Redirection option 2
if ($value == 'YOUR_VALUE_2')
{
    $submission->form->successurl = 'https://site.com/page2';
}

The PHP code above reads the value of the YourTextFieldName field and, depending on its value, sets the redirect URL to the $submission->form->successurl property. Ensure you've replaced the YourTextFieldName with your field's name before using it.

For more details on using PHP Scripts in Convert Forms, check out our documentation.