Php Laravel 5验证-表单元素上的错误类
我的验证表单工作正常,如下所示:Php Laravel 5验证-表单元素上的错误类,php,css,laravel,laravel-4,laravel-5,Php,Css,Laravel,Laravel 4,Laravel 5,我的验证表单工作正常,如下所示: {!! Form::email('email', null, array('placeholder' => 'Email', 'class' => 'form-control ')) !!} {{$errors->first('email')}} {!! Form::email('email', null, array('placeholder' => 'Email', 'class' => 'form-control ' . $
{!! Form::email('email', null, array('placeholder' => 'Email', 'class' => 'form-control ')) !!}
{{$errors->first('email')}}
{!! Form::email('email', null, array('placeholder' => 'Email', 'class' => 'form-control ' . $errors->first('email', 'has-error'))) !!}
如果邮件不好,我会得到这个错误:邮件已经被接收了
问题是,我不想在输入中添加css类,比如error
,以便在输入中添加红色背景边框
如何执行此操作?添加自定义错误消息
'custom' => array(
'email' => array(
'required' => 'We need to know your e-mail address!',
),
),
您只需在其周围添加HTML,并根据需要设置样式即可 HTML: 编辑:将
has error
类添加到输入本身,如下所示:
{!! Form::email('email', null, array('placeholder' => 'Email', 'class' => 'form-control ')) !!}
{{$errors->first('email')}}
{!! Form::email('email', null, array('placeholder' => 'Email', 'class' => 'form-control ' . $errors->first('email', 'has-error'))) !!}
将类添加到窗体时出现如下错误
{!! Form::email('email', null, array('placeholder' => 'Email', 'class' => 'form-control has-error')) !!}
<input class="form-control {{ $errors->has('email') ? 'has-error' : '' }}" name="email" placeholder="Email">
您可以使用if条件如果出现错误,请在中设置类
@if($errors->has('email'))
{!! Form::email('email', null, array('placeholder' => 'Email', 'class' => 'form-control has-error')) !!}
@else
{!! Form::email('email', null, array('placeholder' => 'Email', 'class' => 'form-control')) !!}
@endif
或者你可以这样做
{!! Form::email('email', null, array('placeholder' => 'Email', 'class' => 'form-control has-error')) !!}
<input class="form-control {{ $errors->has('email') ? 'has-error' : '' }}" name="email" placeholder="Email">
您可以使用检查错误的if条件:
{!!Form::text('email',null,['class'=>'Form-control','placeholder'=>'email Address'])
{!!$errors->first('email',':message')
如果({{$errors->has('email')}){
$(输入[type=“email”]).css('border-color','red');
}
这是我的正确答案,没有使用额外的div
:
{!! Form::email('email', null, $attributes = $errors->has('email') ? array('placeholder' => 'Email', 'class' => 'form-control has-error') : array('placeholder' => 'Email', 'class' => 'form-control')) !!}
{{$errors->first('email')}}
您可以使用以下代码检查电子邮件字段是否存在任何验证错误
<div class="form-group has-feedback @if($errors->has('email') has-error @endif">
<input name="email" class="form-control"/>
<span class="glyphicon glyphicon-user form-control-feedback"></span>
@if ($errors->has('email')) <p class="help-block"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
{{ $errors->first('email') }}</p>
@endif
</div>
@如果($errors->has('email'))
{{$errors->first('email')}
@恩迪夫
我不需要自定义错误消息。我需要一个css类添加到我的输入。我不需要创建新元素。我需要一个css类添加到我的电子邮件输入。有一个非常简单的解决方案。:)检查我的编辑。该类仅在表单验证失败时出现,并不总是如您所建议的那样。此类的问题是输入不接受。引导中有错误类。这需要从父div应用。否则,这是一个很好的解决方案。当您试图实现主题/样式化表单时,这是一个有用的答案。注意第一个div类中的语法错误;if语句(括号)缺失