00 Votes

HTML5 Validator: Bad value "" for attribute "action" on element "form": Must be non-empty

Question by Compi | 2016-02-21 at 18:44

I have turned my website into HTML 5 and at the moment, I am trying to validate it.

Among others, the HTML Validator is showing the following error.

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

How can I fix that? Apparently, the validator is moaning because I have left the "action" of my form empty.

However, I have done that even intentionally so that the script is always sending to the current page independent from the page you have called at the moment.

<form action="" method="post">
  <input type="input" name="name">
  <input type="submit" name="submit" value="Send">
</form>

The form is also working perfectly and also the HTML 4 Validator is not disturbed. What am I doing wrong here?

ReplyPositiveNegativeDateVotes
Avatar
0Best Answer2 Votes

You could just write action="#" instead of leaving it empty. This makes the attribute "action" non-empty so that the error message will no longer be displayed and at the same time, the script still remains independent from the page from which it was called.

This would switch your form to that:

<form action="#" method="post" id="myform">
  <input type="input" name="name">
  <input type="submit" name="submit" value="Send">
</form>

If you only want to have the # within your HTML code, you can also try to remove it with JavaScript after parsing:

document.getElementById("myform").setAttribute("action", ""); 

To ensure that the attribute is removed from the correct form, I have added the ID "myform" to your form, so that we can properly access it.
2016-02-21 at 19:54

ReplyPositive Negative
Avatar
00 Votes

You can also use PHP in order to always insert the current page as action-attribute.

For example like that:

<form action="<?php 

echo htmlspecialchars($_SERVER["PHP_SELF"]);

?>" method="post" id="myform">
  <input type="input" name="name">
  <input type="submit" name="submit" value="Send">
</form>

Of course, if it is not necessary to make it dynamic and if you know the recipient page, the easiest way would be to just insert the recipient page behind "action" to get rid of this error.
2016-02-23 at 20:15

ReplyPositive Negative
Reply

Related Topics

"G" or "E" sign on my mobile

Question | 1 Answer

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.