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.
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.
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.
Actually, the Form Submission subsection of the current HTML5 draft does not allow
action=""
. It is against the spec.The quoted section in mercator's answer is a requirement on implementations, not authors. Authors must follow the author requirements. To quote How to read this specification:
The change from HTML4—which did allow an empty URL—was made because “browsers do weird things with an empty
action=""
attribute”. Considering the reason for the change, its probably best not to do that in HTML4 either.I normally use action="", which is XHTML valid and retains the GET data in the URL.