So I have these inputs from my form firstname
, lastname
, username
, email
, password
.
But I only want to complete the registration form and save it into my DB when all of these contain any info given by the user. I have this right now but it only shows an error if the password and/or password confirmation field do not match.
if( !empty ($_POST)){
if($_POST['password'] == $_POST['password_confirmation']) {
$user = new User();
$user->setFirstName($_POST['firstname']);
$user->setLastName($_POST['lastname']);
$user->setUsername($_POST['username']);
$user->setEmail($_POST['email']);
$user->setPassword($_POST['password']);
if($user->register()){
$user->login();
}
else{
$error_confirmation = true;
// This gives error in the front end if both of the PW do no match each other
}
}
I guess I am supposed to do something like this?
if( !empty ($_POST['firstname']) && !empty ($_POST['lastname']) && !empty ($_POST['username']) && !empty ($_POST['email']) && !empty ($_POST['password'])){
Aucun commentaire:
Enregistrer un commentaire