Symfony:在验证之前/之后预过滤提交的值
我一直在网上搜寻,但什么也没找到!
我正在使用 symfonys 表单框架来构建一个简单的“创建”表单。验证没问题。不过,我想预先过滤我提交的值,因此添加 ucfirst、strtoupper 等。
我不确定我是否在这里遗漏了一些关键的东西,但我认为唯一的方法是创建我自己的自定义验证器并利用 doClean 方法,这似乎很愚蠢,因为我有数百个验证器对于每个 php 函数!
希望你们能提供帮助,我一直在爬行源代码、API、大量书籍和博客,但我还没有找到任何东西:(要么这是不可能的,要么它真的很容易,我希望是后者!
I've been scouring the net and i have found nothing!
I am using symfonys form framework to build a simple 'Create' form. Validation is fine. However i'd like to pre-filter my submitted values, so adding ucfirst, strtoupper, and the like.
I'm not sure if im missing something crucial here, but the way i see it is the only way to do this would be to create my own custom validators and utilizing the doClean method, which seems daft since i'd have hundreds of validators for each php function!
Hope you guys can help, i've been crawling through source code, api's, numerous books and blogs and i haven't found a thing :( Either it's impossible, or it's really easy, i hope its the latter!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于可能没有回答这个问题,我深表歉意,但是您能否澄清为什么在绑定和验证之前需要更改这些值?这似乎可以作为 sfFormDoctrine::processValues 的一部分或在 sfFormDoctrine::updateXXXXColumn 回调中完成。如果你使用 Propel,应该有类似的方法。
I apologize for possibly not answering the question, but can you clarify why the values need to be changed prior to binding and validating? This seems like something that could be done as part of
sfFormDoctrine::processValues
or in thesfFormDoctrine::updateXXXXColumn
callbacks. If you're using Propel, there should be similar methods.