html form submit to different action depending on properties

Sometimes you want the form to submit to different URL based on which submit button you click. This is already supported by HTML with formaction attribute


 <form action="/action_page.php" method="get">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>

  <button type="submit">Submit</button>
  <button type="submit" formaction="/action_page2.php">Submit to another page</button>

More information on the attirbute

Last updated