0

我正在尝试对我的表单进行后端验证,但它不起作用。即使我提交了值,它也总是显示验证失败。

代码

$validation = Validator::make(Input::all(), array(
    array('email' => 'required'),
    array('password' => 'required')
));

if ($validation->fails()) { // This is always failing
    echo '<pre>';
    print_r(Input::all());
    die();
}

die('everything is OK!');

输出

Array
(
    [_token] => ZnzZ2aDoTABIZZkvwxZoa7IjHkvK25ndibis5AbA
    [email] => somedata
    [password] => somemoredata
)

如您所见,即使从Input:all()设置的值中清楚地表明它也失败了。

4

2 回答 2

6

尝试这个 :

$validation = Validator::make(Input::all(), array(
    'email' => 'required',
    'password' => 'required'
));

不像你做的那样双数组:

$validation = Validator::make(Input::all(), array(
    array('email' => 'required'), // Is shouldn't be an array here.
    array('password' => 'required')
));
于 2013-09-22T18:23:07.327 回答
4

改变:

$validation = Validator::make(Input::all(), array(
    array('email' => 'required'),
    array('password' => 'required')
));

$validation = Validator::make(Input::all(), array(
    'email' => 'required|email',  // Note that I added in valid email rule here also
    'password' => 'required'
));
于 2013-09-22T16:44:59.113 回答