views:

349

answers:

2

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 ;

a) How does Django insert the action?

b) Why do they do it like this?

b) 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.

+3  A: 

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.

yaauie
ah. I didn't know that. So is this just laziness or is it good practice to rely on this
interstar
i'd say good practice, since you reduce the number of urls in your code. but I prefer not putting the action at all. does any browser out there need the empty action?
Javier
Forms without action attrbiute work fine in all mainstream browsers. However the action attribute is mandatory if you want your HTML to validate.
Imran
+1  A: 

It's also possible that javascript loaded with this page could be setting an action once the page is loaded based on what application is using the page.

Another likely possibility is that the javascript is handling the onsubmit event. One might do that to prevent the page from reloading or redirecting to a specific page

jottos