Kohana3 对带有 [] 的字段进行验证
我有一个包含复选框的表单。
<input type="checkbox" name="question[5][13]" value="1" />
现在,我想使用 Kohana 验证类,但它似乎不验证数组字段...有人曾经解决过吗?
我有这样的东西,但它不会工作:
$rules->rule('question[5][13]', 'not_empty');
I have a form that contains checkboxes.
<input type="checkbox" name="question[5][13]" value="1" />
Now, I want to use the Kohana validation class, but it seems like it does not validate fields that are array... had anyone ever worked something around?
I have something like this, but it will not work:
$rules->rule('question[5][13]', 'not_empty');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你有一个数组而不是你应该验证它的值,而不仅仅是一个值,那么没有什么可以解决的,对吧?
因此,如果您的值中有一个需要验证的“问题”键,您可能应该对其进行自定义验证回调,对吗?
所以..
...应该可以完成这项工作,只要您在回调中正确验证所有问题或其他内容。
There's nothing to work around, if you're having an array than you're supposed to validate it's values, not only one value, right?
So, if you have a 'question' key in your values that are supposed to be validated, you should probably make a callback with custom validation for it, right?
so..
... should probably do the job, as long as you validate all questions or whatever properly in the callback.
当前的 Kohana 3 验证类 (3.0.7) 只能将整个数组作为一项进行验证。
您必须按照 Kemo 的建议使用自定义回调来自行验证整个数组。
开发人员正在考虑彻底修改验证类,但我不确定这是否是他们正在考虑的事情之一。
Formo 2 计划支持这种形式,但我不确定距离有多近这部分的完成度是。
The current Kohana 3 validation classes (3.0.7) can only validate the whole array as one item.
You will have to use a custom callback to validate the whole array yourself as Kemo suggested.
The devs are looking at overhauling the validation classes, but I'm not sure if this is one of the things they're considering.
Formo 2 is planning to support this sort of form, but I'm not sure how close to completion this part is.