【发布时间】:2018-04-17 09:21:15
【问题描述】:
我正在使用我正在使用 laravel 5.5 和 laravel collective 来构建我的表单。
在验证期间,为了管理错误和恢复旧值,我使用了这种代码:
<div class="@if ($errors->has( $question->title )) has-error @endif">
{!! Form::label($question->title, $question->title) !!}
{!! Form::text($question->title, null, ['class' => 'form-control']) !!}
@if ($errors->has($question->title)) <p class="help-block">{{ $errors->first($question->title) }}</p> @endif
</div>
一切运行良好。但是我遇到了一个问题,我的name 属性包含空格。
当页面显示时,我的name 属性用空格写得很好,例如Are you happy?
但验证返回错误提及Are_you_happy?,因此旧值不会被放回,并且由于_ 而不会显示错误消息。
我正在考虑使用正则表达式来“清理”表单中的值,但错误消息仍然是 The Are_you_happy? field is required. 所以不太好。
是否有任何技巧或更好的方法来进行? 还是有空格只是一种不好的做法?
更多信息
点字符 . 也会出现这种情况,在验证期间它会被 _ 替换。
【问题讨论】:
标签: php forms laravel laravel-5