I have a regular form on my php file, after it's submitted it has to echo a message. By putting anything in the action="", the only way I can think of displaying a message is by storing it into a session and display it when the page loads if there is a session set.
Everything works fine the way it is right now but w3c validator says I have an error:
Bad value for attribute action on element form: Must be non-empty.
How can I fix this error without having to put # or index.php into the action field?
EDIT:
<form action="" method="post">
<input type="email" name="email" placeholder="Enter your email">
<input type="submit" name="submit" value="SEND">
</form>
<?php
if(isset($_POST['submit']) && isset($_POST['email'])){
if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false){
echo 'This isn\'t a valid email';
}else{
echo 'Great';
}
}
?>
Maintainer of the W3C HTML Checker (validator) here. If your goal is just to get the checker to not emit that error, one way to do that is to go ahead and put #
as the value for the action
attribute in your HTML source, but then remove it using JavaScript, like this:
<form action="#" method="post">
<script>document.querySelector("form").setAttribute("action", "")</script>
<input type="email" name="email" placeholder="Enter your email">
<input type="submit" name="submit" value="SEND">
</form>