I’ve a basic login form to which I want to add some validations. I came up with these:
$errors = array();
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(0 === preg_match("/.+@.+\..+/", $_POST['email'])){
$errors['email'] = "Please enter a valid email address";
}
if(0 === preg_match("/.{6,}/", $_POST['password'])){
$errors['password'] = "Please enter you correct password";
}
if(0 === count($errors)){
// SUBMIT THE FORM, <form action='auth.php' method='post'...
}
}
So, how can I accomplish the last IF part, which will submit the form if there’s no error? Thanks in advance
I would imagine if this code is in
auth.phpthen you are already submitting the form.Think of it this way: You submit the form no matter what, but stop the submission if there are errors. You process may look something like the following:
form.php
auth.php