sfValidatorChoice 不适用于多重选择元素

发布于 2024-09-26 06:55:39 字数 553 浏览 0 评论 0原文

sfValidatorChoice 不适用于多个选择元素,我的代码

$this->form=new MyTestForm();
$options_array=array("php","python","java");
$widgetSchema["my_select"] =new sfWidgetFormChoice(array('choices'  =>  $options_array,'multiple' => true,'expanded' => true ));
                $validatorSchema["my_select"] = new sfValidatorChoice(array("choices" =>array_keys($options_array)));

注意:我还尝试使用 array_keys 并直接将数组传递给 sfValidatorChoice。

当我提交时,它给出了 Invalid 错误(选中时)和 Required(未选中时)。 参数有错误或者是bug吗?

sfValidatorChoice is not working on multiple select element, my code

$this->form=new MyTestForm();
$options_array=array("php","python","java");
$widgetSchema["my_select"] =new sfWidgetFormChoice(array('choices'  =>  $options_array,'multiple' => true,'expanded' => true ));
                $validatorSchema["my_select"] = new sfValidatorChoice(array("choices" =>array_keys($options_array)));

Note: i have also tried using array_keys and by directly passing the array to sfValidatorChoice.

when i submit, it gives me Invalid error(when checked) and Required(when unchecked).
is there any error in parameters or is bug?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情空心 2024-10-03 06:55:40

首先,您需要在验证器和小部件中启用“多个”:

"multiple" => true

要使任何选择可选,您需要将 required 设置为 false

"required" => false

最后,我不记得如何使用 sfValidatorChoice (已经有一段时间了),但我认为最好使值可读,所以我会这样做:

$options_array=array('php'=>'php','python'=>'python','java'=>'java');

我不确定这会解决问题,但它可能会解决问题。

Firstly, you need to enable "multiple" in the validator as well as the widget:

"multiple" => true

To make having any selection optional, you need to set required to false:

"required" => false

Finally, I can't exactly remember how to use sfValidatorChoice (it's been a while), but I think it's best to make the values readable, so I'd do:

$options_array=array('php'=>'php','python'=>'python','java'=>'java');

I'm not certain this will fix the problem, but it may well do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文