W3docs

submit a form in a new tab

To open a form submission in a new tab, you can use the target attribute of the form element and set it to _blank.

To open a form submission in a new tab, you can use the target attribute of the form element and set it to _blank. This is a standard HTML attribute, not specific to any server-side language. Here is an example:

How to submit a form in a new tab?

<form action="/submit-form.php" method="post" target="_blank">
  <!-- form elements go here -->
  <button type="submit">Submit</button>
</form>

This will open the form submission in a new tab. The action attribute specifies the URL of the page that will handle the form submission, and the method attribute specifies the HTTP method that will be used to submit the form (either "get" or "post").

You can also use JavaScript to open the form submission in a new tab. Note that calling window.open() after event.preventDefault() may trigger browser pop-up blockers. A more reliable approach is to set the form's target dynamically and submit it:

Example using JavaScript

<form id="my-form" action="/submit-form.php" method="post">
  <!-- form elements go here -->
  <button type="submit">Submit</button>
</form>

<script>
  var form = document.getElementById('my-form');
  form.addEventListener('submit', function(event) {
    form.target = '_blank';
    form.submit();
  });
</script>

This will open the form submission in a new tab when the form is submitted.