Symfony:如何更改操作中的表单字段属性? [英] Symfony: How to change a form field attribute in an action?
问题描述
我有一个函数形式的sfWidgetFormChoice作为复选框的列表。我可以通过以下选项将复选框设置为已选中:
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'))
...其中复选框称为状态,可能的值为1/2/3 。
... 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');
任何人?
p>
推荐答案
您的语法似乎根据 sfForm 和 sfWidget API文档。
Your syntax seems valid according to the sfForm and sfWidget API documentation.
这篇关于Symfony:如何更改操作中的表单字段属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!