如何检查电子邮件和密码的验证格式并确认密码? 如何返回必填字段的错误。
这是我的无脂肪功能 -
$f3->route('GET|POST /addstep',
function($f3) use ($db){
$idss = $f3->get('SESSION.id');
//print_r($_SESSION);die;
$data = json_decode($f3['BODY']);
$title = $data->title;
$first_name = $data->first_name;
$middle_initial = $data->middle_initial;
$last_name = $data->last_name;
$email = $data->email;
$password = $data->password;
$confirm_password = $data->confirm_password;
$tax_id = $data->tax_id;
});
答案 0 :(得分:1)
我创建了一个可以帮助你的小插件。
检查Fat Free Framework Validator
小例子:
$data = $f3->get('POST')
$valid = Validate::is_valid($data, array(
'username' => 'required|alpha_numeric',
'password' => 'required|max_len,100|min_len,6'
));
if($valid === true) {
// continue
} else {
print_r($valid); // the invalid items
}
答案 1 :(得分:0)
检查f3-validator,它还支持基于模型的验证。
例如:
$rules = array(
'email' => 'email|unique:users', // uniqueness of email in users table
'password' => 'required|confirmed|min:3|max:20', // confirm password
'name' => 'required|between:6,12'
);
起爆:
$validator = Validator::instance()->validate($data, $rules);
OR
$validator = new Validator($data, $rules);
$validator->validate();
检查:
$validator->passed(); // return true|false
获取错误:
$validator->errors();