0

它不检查提到的字段是否存在。两个版本

第一个版本:

$error = array();
$field_sets = array('username','password','fullname','repeatpass','email');
foreach($field_sets as $fieldname){
    if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) {
        $error[] = $fieldname;
    }
}

第二版:

(in the includes file)
function check_required_fields ($required_array){
    $error = array();
    foreach($required_array as $fieldname){
        if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) { 
            $error[] = $fieldname;
        }
    }
    return $error;
}

In the Source File:
$error = array();
$required_field = array('username','password','fullname','repeatpass','email');
$error = array_merge($error , check_required_fields($required_field , $_POST));
4

1 回答 1

0

我发现了问题。我不小心把&&逻辑放进去了。它应该||代替&&.

          if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) || $_POST[$fieldname] != 0))
于 2012-05-05T14:09:24.133 回答