PHPフォーム検証
819 ワード
exit()後続スクリプトの実行を停止
単一フィールドブランク判定
全フィールドブランク判定
それ以外は空白判定
単一フィールドブランク判定
if(empty($_POST['last_name']))
{
echo "You did not enter your last name.
Last name is required.
";
redisplay the form;
exit();
}
echo "Welcome to the Members Only club.
You may select from the menu below.
";
display the menu;
全フィールドブランク判定
foreach($_POST as $value)
{
if($value == "")
{
echo "You have not filled in all the fields.
";
redisplay the form;
exit();
}
}
echo "Welcome";
それ以外は空白判定
foreach($_POST as $field => $value)
{
if($value == "")
{
if($field != "fax" and $field != "middle_name")
{
echo "You have not filled in $field
";
display the form;
exit();
}
}
}
echo "Welcome";