As of HTML5, the widely used and recommended action=""
is invalid HTML.
From the specs:
The action and formaction content attributes, if specified, must have a value that is a valid URL.
So what is the correct way to have the action
attribute point to the current page?
I am currently using
action="<php htmlspecialchars($_SERVER["REQUEST_URI"]); ?>"
No, in HTML5, the
action
attribute may be omitted, and it defaults to the emoty string, which means a reference to the current document.It's true that the
action=
attribute may not be empty, as an empty string is not a valid URL. However, it is valid to simply leave it out, and let the browser figure it out.The browser will assume the current page.
You can set value to '.' or do not set action attribute at all.
(I was surprise but it is really invalid to leave it blank, at least validator.w3.org is returning error).