8

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!

Pi Delport
  • 10,356
  • 3
  • 36
  • 50
user1002039
  • 860
  • 4
  • 17
  • 31

2 Answers2

8

Simply put in "#".

<form action="#" method=post>
mo.
  • 89
  • 1
  • 1
  • I'm pretty sure it's valid in html5 but I'm affraid, do you think it could cause problem with old browser? Acting like an anchor instead of sending the POST request to the current pas ? – Yann Chabot May 15 '15 at 10:38
  • [Similar question](http://stackoverflow.com/questions/8395269/what-do-form-action-and-form-method-post-action-do), similar answers :) – CoR Jul 14 '15 at 11:16
4

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.

Michael Grassman
  • 1,935
  • 13
  • 21