### [How To Open a New Link on Form Submission with AJAX](https://wpforms.com/developers/how-to-open-a-new-link-on-form-submission/)

**Published:** June 24, 2021
**Author:** Editorial Team

**Excerpt:** This tutorial will walk you through how to open a new link on a form that has AJAX enabled when the users click Submit using a small code snippet. 

**Content:**

Would you like to open a new link on form submissions when you have AJAX enabled? Using a small code snippet, we’re going to show you how you can display your confirmation message but also open a new link when the form is submitted.

By default, WPForms gives you the option of displaying a confirmation message, redirecting to a page on your site, or providing a custom URL when the form is submitted. But what if you wanted to do a combination of these options? For this tutorial, we’re going to create a form that will display a confirmation message when the form is submitted but also open a new tab and load a page that displays a PDF download as well.

## Creating the form

First, we’ll need to create our form. Our form is a simple newsletter sign-up form but we’re also going to allow them to provide any feedback comments as well so we’ll have the **Name**, **Email**, and **Paragraph Text** form fields in our form.

If you need help in creating your form, [please see this documentation](https://wpforms.com/docs/creating-first-form/ "Creating Your First Form").

![create your form and add your fields](https://wpforms.com/wp-content/uploads/2021/06/wpforms-ajax-new-window-link-create-form.jpg)

Before exiting the form builder, be sure to select the **Enable AJAX form submission** on the **General** tab.

![be sure to enable ajax from the general settings tab](https://wpforms.com/wp-content/uploads/2021/06/wpforms-ajax-new-window-link-ajax-setting.jpg)

Since we will be defining the link inside the code snippet, you can leave the **Confirmations** tab **Confirmation** type to just display your confirmation message.

![Since we will be defining the link inside the code snippet, you can leave the Confirmation type to just display your confirmation message.](https://wpforms.com/wp-content/uploads/2021/06/wpforms-ajax-new-window-link.jpg)

## Opening a new link on form submission

Now it’s time to add the snippet that will open a new link on form submissions.

If you need any help in adding snippets to your site, [please review this tutorial](https://wpforms.com/developers/how-to-add-custom-php-or-javascript-for-wpforms/ "How to Add Custom PHP or JavaScript for WPForms").

This particular snippet will only work if AJAX is enabled on the form submission.

```

/**
 * Open new link on form submission with AJAX
 *
 * @link https://wpforms.com/developers/how-to-open-a-new-link-on-form-submission
 */
  
function wpf_dev_event_after_submit() {
   ?>

**Categories:** Extending

**Tags:** Javascript, JS

---

