hi
Im using Respect validation and would like to add a custom error message to it.
I dont what to display the “fname not alphanumeric” in the message it must display “First name not alphanumeric”
//UserController
class UserController extends BaseController {
public function postSignUp(SEmail $semail, View $view) {
$validation = $this->validator->validate($this->request, [
'fname' => v::notBlank()->alpha(' '),
'lname' => v::notBlank()->alpha(' '),
]);
if ($validation->failed()) {
return $this->redirect('auth.signup');
}
// do more stuff
}
//Validator.php
namespace Ti\Support\Validation;
use Ti\Support\Validation\Contracts\ValidatorInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Respect\Validation\Exceptions\NestedValidationException;
class Validator implements ValidatorInterface {
protected $errors = [];
public function validate(Request $request, array $rules) {
foreach ($rules as $field => $rule) {
try {
$rule->setName(ucfirst($field))->assert($request->getParam($field));
} catch (NestedValidationException $e) {
$this->errors[$field] = $e->getMessages();
}
}
$_SESSION['errors'] = $this->errors;
return $this;
}
public function failed() {
return !empty($this->errors);
}
}