I've got a exercise to make a , and validate that with php. Why it don't give out a error message?
If I check the name only about the length then it works. And if I check the name only about the right character then it also works. Whats wrong by //Error check?
<?php
//Values set?
if(isset($_POST['name'])){
$errors = [];
//Error check
if (!preg_match("/^[a-zA-Z ]*$/",$_POST['name']) && strlen($_POST['name']) < 2) {
$errors['name'] = 'Please put in your name.';
}
}
?>
<p>Input your name</p>
<?php
//Show Errors
if (isset($errors['name'])){
echo '<p>' . $errors['name'] . '</p>';
}
?>
<input type="Text" name="name">
<input type="submit" name="submit" value="send">
Aucun commentaire:
Enregistrer un commentaire