I want to avoid to validate the form if the user enters white spaces,
but actually entering spaces the form is still validate...
<?php
$name = ""; $email = ""; $comment = ""; $website = "";
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if(!empty($_POST["name"]) && !empty($_POST["email"]) && !empty($_POST["website"]) && !empty($_POST["comment"])){
$name = test_input($_POST["name"]);
$email = test_input($_POST["email"]);
$website = test_input($_POST["website"]);
$comment = test_input($_POST["comment"]);
echo htmlspecialchars("".$name."".$email."".$website."".$comment."");
}else{
echo htmlspecialchars("fill all fields");
}
}
function test_input($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
What I am doing wrong?