我的php表单包含必填字段,但该消息不会让用户知道哪个字段尚未输入.我怎样才能做到这一点?
//if statement to check required fields
if ($name && $phone && $email && && $address && $city && $state && $zip && $month && $date && $year && $contact)...
//if some required fields were not filled out
echo "Please make sure you fill in all required fields<br>Click <a href=\"javascript:history.back(1)\">here</a> to return to our form.";
}
Run Code Online (Sandbox Code Playgroud)
这是一个微不足道的例子......
// An array of required fields, these fields must not be empty
$requiredFields = array('name', 'email');
// Iterate through required fields
foreach ($requiredFields as $fieldName)
{
// Does this field have a value?
if (empty($_REQUEST[$fieldName]))
{
echo 'rawr! go back and fill out ' . $fieldName . "<br>\n";
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1722 次 |
| 最近记录: |