Symfony:如何更改操作中的表单字段属性?

发布于 2024-08-21 02:23:29 字数 532 浏览 3 评论 0原文

我有一个带有 sfWidgetFormChoice 的功能表单,它充当复选框列表。我可以通过以下方式将复选框默认设置为“勾选”:

'status' => new sfWidgetFormChoice(array('choices' => array(1, 2, 3), 'multiple' => true, 'expanded' => true), array('checked' => 'checked'))

...其中复选框称为“状态”,可能的值为 1/2/3。

然而,由于其他原因,我希望能够通过操作控制“已检查”状态,而不是默认情况下全部勾选。我该怎么做?我已经尝试了我能想到的所有逻辑,但我就是无法找出正确的语法。

基本上,我正在寻找类似的东西:

$this->form->getWidget('status')->setAttribute('checked', 'checked');

有人吗?

谢谢。

I've got a functioning form with a sfWidgetFormChoice that acts as a list of checkboxes. I'm able to set the checkboxes to "ticked" by default with the following:

'status' => new sfWidgetFormChoice(array('choices' => array(1, 2, 3), 'multiple' => true, 'expanded' => true), array('checked' => 'checked'))

... where the checkboxes are called "status" and the possible values are 1/2/3.

However, because of something else, instead of ticking them all by default I'd like to be able to control the "checked" status from an action. How do I do this? I've tried everything logical I can think of but I just can't figure out the right syntax.

Basically, I'm looking for something like:

$this->form->getWidget('status')->setAttribute('checked', 'checked');

Anyone?

Thanks.

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

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

发布评论

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

评论(1

〃安静 2024-08-28 02:23:29

根据 sfFormsfWidget API 文档。

Your syntax seems valid according to the sfForm and sfWidget API documentation.

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