简体   繁体   English

2页验证错误处理Symfony 2

[英]2 page validation error handling Symfony 2

I've got a comment form on my page (commentlist) and want validate this. 我的页面(评论列表)上有一个评论表单,并希望对此进行验证。 The form submits to another url: comment/add. 表单提交到另一个URL:注释/添加。 The validation itself works perfectly but I can't display the messages with form_errors(form) into the form field. 验证本身可以正常工作,但是我无法将带有form_errors(form)的消息显示到form字段中。

I know this is because the validation exists out of 2 pages. 我知道这是因为验证存在于2页之外。 So it's being validated but then redirected again to the page so that it looks like there are no mistakes. 因此它正在被验证,但随后再次重定向到该页面,以便看起来没有错误。

my question: What's the best way to transfer the messages to my formpage so that I can show them to the user? 我的问题:将消息传输到表单页面以便向用户显示消息的最佳方法是什么? Preferabbly to keep the submitted message. 最好保留提交的消息。

You can use the flash messages. 您可以使用Flash消息。 You can set the message into the action: 您可以将消息设置为操作:

$this->get('session')->setFlash('my_flash_key',"Flash label!");

and you can show it into the template: 您可以将其显示到模板中:

 {% for key, flash in app.session.getFlashes() %}
    <div class="errors">
        {{ flash }}
    </div>
{% endfor %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM