通常,当我创建表单时,在数据输入错误的字段下会显示错误。
代码看起来像这样
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name" class="control-label">Imie</label>
<div class="col-md6">
<input id="name" maxlength="255" type="text" class="form-control" name="name" required autofocus>
@if ($errors->has('name'))
<span class='help-block'>
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
</div>
</div>
我有一个来自客户的规范,不告诉用户错误填写了哪个字段,我想知道如何使它看起来像这样
最佳答案
我建议删除单输入中的所有错误消息,并像这样仅在顶部放置一个:
@if (!empty($errors))
<span class='help-block'>
<strong>{{ "Some input field is not properly filled" }}</strong>
</span>
@endif
并且所有输入字段都应该是这样的:
<div class="form-group">
<label for="name" class="control-label">Imie</label>
<div class="col-md6">
<input id="name" maxlength="255" type="text" class="form-control" name="name" required autofocus>
</div>
</div>
现在,如果您在任何字段中都有错误,那么您将获得该消息的顶部。
关于php - Laravel如何在错误填写表单字段时引发单个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44613725/