is there any chance in Laravel 4 to simply add a class e.g. "error" to a form field after validation error? I thought the Form Helper will do that...
Thanks Regards
Yeah, you just have to check your errors for a certain error on a field when outputting the form field, and if it has an error, give it the class of error. I'm not sure of your variable names, but hopefully you get the idea...
// Some validation
$validator = Validate::make($input, $rules);
// If it fails, pass errors into view.
// This could be confusing, you should check http://laravel.com/docs/validation#error-messages-and-views for more info
if($validator->fails()) {
return View::make('someform')->withErrors($validator);
}
// withErrors() will flash the validation messages to an errors variable.
//This is just some shorthand syntax that's checking for an error on email and if there is something, it will give the class of error else it will give a blank class
{{ Form::text('email', array('class' => $errors->has('email') ? 'error' : '')) }}
code{{Form::text('username', '', array('class' => 'form-control')) }}code so how can I extend my class="form-control" or is there any other way to add error class? Thanksform-control class, just add that to both scenarios. {{ Form::text('username', array('class' => $errors->has('username') ? 'form-control error' : 'form-control')) }}