Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Forms without actions

In Django / Pinax, I've come across the login form which starts like this :

<form class="login" method="POST" action=""> 

It works perfectly well. So I assume that either some java-script or something in the Django framework is putting the value into the action attribute.
So, my questions:

  • How does Django insert the action?
  • Why do they do it like this?
  • How can I find out what the action of this form is?

Update : I see this is not a Django thing at all, but what most browsers do.

like image 514
interstar Avatar asked Mar 13 '09 02:03

interstar


People also ask

Can HTML form without action?

Yes, the form is required to have an action attribute in HTML4. If it's not set, the browser will likely use the same method as providing an empty string to it. You really should set action="" which is perfectly valid HTML4, follows standards, and achieves the same exact result.

How do I disable form action in HTML?

There is a method in Javascript to remove this functionality of the HTML form which name is preventDefault(). preventDefault() method of Javascript can be used with two events - onclick & onsubmit. You need to write something in function's parameter to examine the event to disable it.

What happens if form has no action?

If action is set to "" or if the action attribute is missing, the form submits to itself. That is, if your script is index.

Do you need form action?

Is the action Attribute Required? Back in HTML4, the answer would be yes. Nowadays with HTML5, you are not required to specify an action attribute. If you have a form tag without an action attribute then the data will be sent to its own page.


1 Answers

Having an action of an empty string in most browsers points the form at the URL the browser currently has loaded, which is the script that served the form in the first place.

like image 89
Ry Biesemeyer Avatar answered Oct 09 '22 05:10

Ry Biesemeyer