Hallo so I would like to make my website more interactive. I have registration form I would like to display icons(correct/false)after register button has been clicked, so user can see what field is not correct. This is what I mean.
I know that I need to use:
json_encode
to pass array to ajax file.(But that's all I actually know...)
This is an example of my php code which I would like to use to control register form.
if(isset($_POST['register'])){
$errors = array();
$user = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
if(empty($user)){
$errors[] = "You need to fill username.";
}
if(strlen($password) < 3){
$errors[] = "This Password is to short";
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$errors[] = "This e-mail is not correct ";
}
if(empty($errors)){
$db->query("INSERT INTO users (user,pass,email)VALUES ('$user','$password','$email')");
}
if(!empty($errors)){
json_encode($errors);
}
}
I don't want refresh page. How can I do it? I need help some code and explanation. Thank you very much.
Aucun commentaire:
Enregistrer un commentaire