0

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"]); ?>"
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
Zulakis
  • 7,859
  • 10
  • 42
  • 67

3 Answers3

1

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.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
  • w3Schools says it's "no longer necessary": http://www.w3schools.com/html5/att_form_action.asp Not sure how accurate that is. – Mansfield Oct 01 '12 at 19:55
  • 2
    @Mansfield: w3schools is a wrong and misleading site. You shouldn't use it as reference for any sort of language. For PHP, there's the [PHP Manual](http://php.net), for JavaScript, there's [Mozilla Developer Network (or MDN)](https://developer.mozilla.org/). See http://w3fools.com to further understand why you should never use w3schools. – Madara's Ghost Oct 01 '12 at 19:56
  • Interesting. I never took it as an official source, but I never knew any of that. Thanks for the heads up! – Mansfield Oct 01 '12 at 20:00
0

You can set value to '.' or do not set action attribute at all.

<form method="post">
or
<form method="post" action=".">

(I was surprise but it is really invalid to leave it blank, at least validator.w3.org is returning error).

lupatus
  • 4,208
  • 17
  • 19
0

No, in HTML5, the action attribute may be omitted, and it defaults to the emoty string, which means a reference to the current document.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390