![](/img/trans.png)
[英]Laravel 5.1 How to translate attribute values in the form validation messages?
[英]Laravel 5.1 How to output HTML in form validation error messages
我有一个表单请求类来验证我的数据,我使用messages()
方法返回自定义验证错误消息,如下所示:
public function messages()
{
return [
'name.valid_name' => 'The name is incorrect, please see the <a href="'.route('naming_conventions').'">Naming Conventions</a> page for instructions on naming.'
];
}
因此,您可以看到我想在错误消息中输出超链接以帮助用户。 当输出错误消息时,尽管所有html标记都已转换为实体,因此实际输出的是:
The name is incorrect, please see the <a href="http://local.website.com/naming-conventions">Naming Conventions</a> page for instructions on naming.
如何在错误消息中输出HTML?
事实证明,这是我输出导致HTML实体问题的错误的方式。 我正在做以下事情:
@if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
我不得不将<li>{{ $error }}</li>
更改为<li>{!! $error !!}</li>
<li>{!! $error !!}</li>
不要在邮件本身中放置超链接。 如果响应中返回任何错误消息,请尝试在视图中使用@if @endif
语句
@if($errors and $errors->has('name.valid_name'))
he name is incorrect, please see the <a href="">Help link</a>
@endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.