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.
The best thing you can do is leave out the action attribute altogether. If you leave it out, the form will be submitted to the document's address, i.e. the same page.
It is also possible to leave it empty, and any browser implementing HTML's form submission algorithm will treat it as equivalent to the document's address, which it does mainly because that's how browsers currently work:
This definitely works in all current browsers, but may not work as expected in some older browsers ("browsers do weird things with an empty action="" attribute"), which is why the spec strongly discourages authors from leaving it empty:
IN HTML 5
action=""
IS NOT SUPPORTED SO DON'T DO THIS. BAD PRACTICE.If instead you completely negate action altogether it will submit to the same page by default, I believe this is the best practice:
If you are sumbitting the form using php you may want to consider the following. read more about it here.
Alternatively you could use
#
bear in mind though that this will act like an anchor and scroll to the top of the page.Just use
It doesn't violate HTML5 standards.
I use to do not specify action attribute at all. It is actually how my framework is designed all pages get submitted back exact to same address. But today I discovered problem. Sometimes I borrow action attribute value to make some background call (I guess some people name them AJAX). So I found that IE keeps action attribute value as empty if action attribute wasn't specified. It is a bit odd in my understanding, since if no action attribute specified, the JavaScript counterpart has to be at least undefined. Anyway, my point is before you choose best practice you need to understand more context, like will you use the attribute in JavaScript or not.
This will validate with HTML5.
Not including the action attribute opens the page up to iframe clickjacking attacks, which involve a few simple steps:
References