The formAction attribute in HTML

- Andrés Cruz

En español

The formAction attribute in HTML

Example Download

HTML has a large number of elements and attributes, some of them more useful than others depending on the situation and others quite unknown about which little is said; today I bring you an unknown to many called formAction.

The formAction applicable to submit type inputs overrides the action attribute of the form in which it is contained, which is a quite particular and useful function given the circumstances:

    <form action="controlador1">
      Nombre: <input type="text" name="nombre"><br>
      Apellido: <input type="text" name="apellido"><br>
      <input type="submit" value="Submit 1"><br>
      <input type="submit" value="Submit 2" formaction="controlador2" >
    </form>

If we press the first "Submit" of the form:

<input type="submit" value="Submit 1">

The request will be handled by the program that handles the controller1 URI which is specified in the action attribute of the form.

If, on the other hand, we press the second "Submit" of the form:

<input type="submit" value="Submit 2" formaction="controlador2">

The request will be handled by the program that manages the controller2 URI and this is thanks to the formAction attribute that allows overwriting the URI of the action attribute of the form element that makes up the form.

And this is basically all, it can surely be useful to show/hide some submit type inputs of the form with JavaScript when certain values are present and avoid overwriting the action attribute of the form using JavaScript.

You can try the previous example in the following link:

Example Download

Andrés Cruz

Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz In Udemy

I agree to receive announcements of interest about this Blog.

!Courses from!

10$

On Udemy

There are 1d 18:50!


Udemy

!Courses from!

4$

In Academy

View courses

!Books from!

1$

See the books
¡Become an affiliate on Gumroad!