tags:

views:

2472

answers:

4

I am wondering if anyone can give a "best practices" response to using blank HTML form actions to post back to the current page.

There is a post asking what a blank HTML form action does here and some pages like this one suggest it is fine but I'd like to know what people think.

+3  A: 

I think it's best to explicitly state where the form posts. If you want to be totally safe, enter the same URL the form is on in the action attribute if you want it to submit back to itself. Although mainstream browsers evaluate "" to the same page, you can't guarantee that non-mainstream browsers will.

And of course, the entire URL including GET data like Juddling points out.

Will Morgan
why not editing this into your post?
tharkun
+2  A: 

I normally use action="", which is XHTML valid and retains the GET data in the URL.

Juddling
you use GET for forms?
tharkun
Juddling
GET is the default method for forms - it's hardly a bad thing ;-) http://www.w3.org/TR/html401/interact/forms.html#adef-method
NickFitz
+1  A: 

I used to do this a lot when I worked with Classic ASP. Usually I used it when server-side validation was needed of some sort for the input (before the days of AJAX). The main draw back I see is that it doesn't separate programming logic from the presentation, at the file level.

busse
why not? I think it's not connected. I can have a form post the data to the same page and build this page with proper separation of controller and view.
tharkun
+7  A: 

HTML5 explicitly mentions as part of its form submission algorithm that an empty action is equivalent to the document's address, which it does mainly because that's how browsers currently work:

8. Let action be the submitter element's action.

9. If action is the empty string, let action be the document's address.

Note: This step is a willful violation of RFC 3986, which would require base URL processing here. This violation is motivated by a desire for compatibility with legacy content. [RFC3986]

In other words, this works now, and will definitely continue to work in the future. In fact, you can leave out the action attribute altogether in HTML5.

I think simplifying your form can only be a good thing.

mercator