有没有更简单的功能,像这样:
if (isset($_POST['Submit'])) { if ($_POST['login'] == "" || $_POST['password'] == "" || $_POST['confirm'] == "" || $_POST['name'] == "" || $_POST['phone'] == "" || $_POST['email'] == "") { echo "error: all fields are required"; } else { echo "proceed..."; } }
像这样:
// Required field names $required = array('login', 'password', 'confirm', 'name', 'phone', 'email'); // Loop over field names, make sure each one exists and is not empty $error = false; foreach($required as $field) { if (empty($_POST[$field])) { $error = true; } } if ($error) { echo "All fields are required."; } else { echo "Proceed..."; }