0
嗨,我想请一些帮助。我有一个验证表单所需字段的函数,其中我传递了req。字段放在数组中,所以如果为空,例如first_name返回错误消息:“first_name为空。” 。问题是我想让邮件中的字段名称对用户看起来更“友好”,没有驼峰或'_'。我怎样才能做到这一点?如何正确显示来自check_required_fields函数的错误消息?
p.s.这里是我的代码:
$required_fields = array('first_name', 'last_name', 'email', 'profileInfo', 'message');
$errors = array_merge($errors, check_required_fields($required_fields));
眼下输出错误信息是这样的: “的FIRST_NAME需要”或“是必需的profileInfo”。 功能是这样的:
function check_required_fields($required_fields) {
$field_errors = array();
foreach($_POST as $field=>$value){
if(empty($value) && in_array($field, $required_fields) === true){
$field_errors[] = "the " . $field . " is required.";
//break 1;
}
}
return $field_errors;
}