When using the W3C validator https://validator.w3.org/ , the following was presented:
Row 1, column 1: document type declaration; will be analyzed without verification
The document type could not be determined because the document did not have the correct DOCTYPE declaration. The document is not like HTML, so automatic rollback cannot be performed, and the document is checked only for the syntax of the basic markup.
Learn how to add doctype to a document from our FAQ or use the Document Type for Authentication parameter to check your document for a specific type of document.
- Along with a few others, but I did not include them here.
Decision:
You need to declare valid doctype and <head><title> tags, as this will also lead to errors if they are omitted.
Then use action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" , As I said in the comments.
Now your code will be checked as follows:
<!DOCTYPE html> <head> <title>Test page</title> </head> <body> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post"> <input type="email" name="email" placeholder="Enter your email"> <input type="submit" name="submit" value="SEND"> </form> </body> </html> <?php if(isset($_POST['submit']) && isset($_POST['email'])){ if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false){ echo 'This isn\'ta valid email'; }else{ echo 'Great'; } } ?>
- Sidenote: you can have PHP on top, both methods checked correctly.
Using action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" , You created the following / similar in the HTML source:
<form action="/folder/file.php" method="post">
While omitting this, you created action="" , which the W3 validator appears to have found invalid and is looking for a valid file for the form action.
Edit:
In light of the recently accepted answer (mine unaccepted), note that your code will not work properly if Javascript is disabled.