<?php
//Form Validation
if(isset($_POST['register']))
{
//Must be at least 4-15 characters and contain letters and numbers
if(!preg_match('/^[a-zA-Z0-9]{4,15}$/', $_POST['username']))
{
$error[]='The username does not match the requirements';
}
//Password validation: must contain at least 1 letter and number. Allows characters !@#$% and be 6-15 characters
if(!preg_match('/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{6,15}$/', $_POST['password1']))
{
$error[]='The password does not match the requirements';
}
//Email validation
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
$error[]='Invalid E-mail';
}
//Output error in array as each line
foreach ($error as $output)
{
echo "$output <br>";
}
}
if ((empty($errors)) && !isset($_POST['register']))
{
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="register">
<input type="text" placeholder="Username" maxlength="15" name="username" value="<?php echo $_POST['username']; ?>" /><br>
<input type="password" maxlength="15" name="password1" /><br>
<input type="password" maxlength="15" name="password2" /><br>
<input type="text" placeholder="your@email.com" maxlength="25" name="email" value="<?php echo $_POST['email']; ?>"/><br>
<input type="text" maxlength="20" name="county" /><br>
<input type="submit" value="Register" name="register"/>
</form>
<?php
}
?>
大家好,
我已经到了没有显示错误的地步,但我可能没有清楚地解释自己。在不再显示错误消息之后,我希望表单不再出现,然后我可以写下“成功”之类的内容。但是我似乎无法做到这一点。