Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Validation - PHP Form Action Attribute Empty

I was just validating some of my html5 pages on W3C with forms (PHP) on them and I get the following validation error:

Error: Bad value for attribute action on element form: Must be non-empty.

I thought that when the form submits to itself, it is good practice to leave the action attribute empty. Is this not the case? How can I fix this?

Thank you!

like image 776
user1002039 Avatar asked Oct 30 '11 22:10

user1002039


People also ask

Which attribute keeps empty forms from being submitted in HTML?

Reading at current HTML5 draf, it seems that empty string is not allowed but the absence of the attribute is allowed. But in any case, for compatibility reasons, I recommend you to always include the "action" attribute and fill it with a valid non-empty URL (good practices are always the best way).

Is form tag empty?

Elements with no closing tag are known as an empty tag. For eg: <br>, <link>, <img>, <hr>, <meta>, <source> etc. Since we can not specify anything in between those. HTML element which does not have a closing tag are called Empty elements.

Is action a valid form tag attribute?

The HTML | action Attribute is used to specify where the formdata is to be sent to the server after submission of the form. It can be used in the <form> element. Attribute Values: URL: It is used to specify the URL of the document where the data to be sent after the submission of the form.

Is form action attribute required?

Yes, the form is required to have an action attribute in HTML4. If it's not set, the browser will likely use the same method as providing an empty string to it. You really should set action="" which is perfectly valid HTML4, follows standards, and achieves the same exact result.


2 Answers

Simply put in "#".

<form action="#" method=post>
like image 66
mo. Avatar answered Oct 27 '22 21:10

mo.


While browsers currently support the empty action since the spec says it's needed browsers in the future may not support it. In my opinion this is unlikely but you never know.

The reason I would add the action attribute is so if there is JavaScript somewhere that is actually posting the form the next developer in line is certain that this is were the form posts to and doesn't have to look though the relevant JavaScript files to see if this is intended or left out on mistake.

It can be fixed my putting the current page in the action attribute.

Hope that helps.

like image 37
Michael Grassman Avatar answered Oct 27 '22 21:10

Michael Grassman