【发布时间】:2015-12-28 00:23:09
【问题描述】:
你好,我有这个表格,我有它的验证。我已经在我的控制器内部完成了对 in 的验证,我已经可以在我的视图中显示错误消息,但我希望错误消息位于它来自的输入区域旁边 这是我在视图中的代码
{{ Form::open(array('url' => 'addParentAccnt')) }}
<div class="form-group">
{{ Form::label('username', 'Username') }}
{{ Form::text('username', Input::old('username'), array('class' => 'form-control','placeholder' => 'Insert username')) }}
</div>
<div class="form-group">
{{ Form::label('fName', 'First Name') }}
{{ Form::text('fName', Input::old('fName'), array('class' => 'form-control','placeholder' => 'Insert First Name')) }}
</div>
<div class="form-group">
{{ Form::label('lName', 'Last Name') }}
{{ Form::text('lName', Input::old('lName'), array('class' => 'form-control','placeholder' => 'Insert Last Name')) }}
</div> {{ Form::submit('Proceed to Next Step', array('class' => 'btn btn-primary')) }}
{{ Form::close()}}
在我的视图底部,我添加了此代码以显示错误消息
@if ($errors->any())
<ul>
{{ implode('', $errors->all('<p style="color:red" class="error">:message</p>')) }}
</ul>
@endif
我的控制器里面的代码是这样的
$rules = array
(
'username' => 'required|min:10|max:50',
'fName' => 'required|alpha|min:1|max:80',
'lName' => 'required|alpha|min:1|max:80',
);
$validator = Validator::make(Input::all(), $rules, $messages);
if ($validator->fails())
{
return Redirect::to('createPa')
->withErrors($validator)
->withInput(Input::except('password'));
}
else
{
//do something
}
【问题讨论】:
标签: laravel laravel-4 laravel-validation