私はそれ自身を提出し、どのような値が入力されたかを示すフォームに取り組んでいます。私はそれがほとんどダウンしているが、私は、ユーザーが値を見逃しているかどうかをチェックし、どの値を逃したかを伝えたい。私はこれをどうやってやるか分かりません。コードは以下の通りです。私はこれが安全ではないことを理解している、私はちょうどこの時点でアイデアを書いている、私はそれをより安全にするために後で修正する。私はいつもちょうど記入必要があるHTMLのフォーム要素で `required`を使用フォーム全体でどのテキストフィールドが空であるかをどのように確認できますか?
<?php
$name = null;
$email = null;
$username = null;
$pwd = null;
$pwd2 = null;
if (!empty($_POST)){
ob_end_clean();
$name = htmlspecialchars($_POST["name"]);
$email = htmlspecialchars($_POST["email"]);
$username = htmlspecialchars($_POST["username"]);
$pwd = htmlspecialchars($_POST["pwd"]);
$pwd2 = htmlspecialchars($_POST["pwd2"]);
if ($pwd == $pwd2){
echo "
<!DOCTYPE html>
<html>
<head>
<title>Week 5 Assignment</title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'/>
</head>
<body>
<p>Welcome $name ! Please review the following information that you submitted:</p>
<p>You entered $email as your email.</p>
<p>You entered $username as your username.</p>
<p>You entered $pwd as your password.</p>
</body>
</html>";
}
else {
echo "
<!DOCTYPE html>
<html>
<head>
<title>Week 5 Assignment</title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'/>
</head>
<body>
<form action="; echo htmlspecialchars($_SERVER["PHP_SELF"]); echo" method=\"post\">
<p> Name: <input type=\"text\" name=\"name\" value=$name></p>
<p>Email: <input type=\"email\" name=\"email\" value=$email></p>
<p>Username: <input type=\"text\" name=\"username\" value=$username></p>
<p>Password: <input type=\"password\" name=\"pwd\" minlength = 4></p>
<p>Retype Password: <input type=\"password\" name=\"pwd2\"></p>
<input type=\"submit\">
</form>
<p>Passwords did not match</p>
</body>
</html>";
}
}
elseif (empty($_POST)){
echo "
<!DOCTYPE html>
<html>
<head>
<title>Week 5 Assignment</title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'/>
</head>
<body>
<form action="; echo htmlspecialchars($_SERVER["PHP_SELF"]); echo" method=\"post\">
<p> Name: <input type=\"text\" name=\"name\"></p>
<p>Email: <input type=\"email\" name=\"email\"></p>
<p>Username: <input type=\"text\" name=\"username\"></p>
<p>Password: <input type=\"password\" name=\"pwd\" minlength = 4></p>
<p>Retype Password: <input type=\"password\" name=\"pwd2\"></p>
<input type=\"submit\">
</form>
</body>
</html>";
}
?>
。複雑なコードを一切必要とせず、何かを提出する前にユーザに警告します。そして、いつものように、サーバ側でも検証を行うべきです。 –
それはうまくいくだろうが、私は冗長性のためにポップもチェックしたいと思う。 –