我一直在使用Respect Validation表單驗證如何從Respect Validation獲取驗證錯誤消息?
$app->post('/', function() use ($app) {
$validator = v::key('name', v::string()->notEmpty())
->key('email', v::email()->notEmpty())
->key('message', v::string()->notEmpty());
$errors = array();
try{
$validator->assert($_POST);
} catch (\InvalidArgumentException $e) {
$errors = $e->findMessages(array(
'notEmpty' => '{{name}} is required',
'email' => '{{name}} must be a valid email'
));
}
if ($validator->validate($_POST)) {
// do stuff
$app->redirect('/');
} else {
$app->render('index.php', array('field_errors' => array_values($errors)));
}
});
通過array_values($errors)
循環會給我:
"" is required
email must be a valid email
我需要這樣的東西:
name is required
email must be a valid email
message is required
究竟應該如何使用Respect Validation完成
我並不積極,但我認爲這與[已知錯誤](https://github.com/Respect/Validation/issues/86)有關。 –