Forms 选择的问题
我的选择有些问题。这是供选择的阵列:Forms 选择的问题,forms,symfony-1.4,Forms,Symfony 1.4,我的选择有些问题。这是供选择的阵列: $branches = array(123 => 'Value 1', 456 => 'Value 2', 789 => 'Value 3') 其中数字是给定的ID。要获得默认值,请执行以下操作: $choices_branches = array_merge(array('default' => 'Bitte wählen'), $branches); $this->setWidgets(array( 'branc
$branches = array(123 => 'Value 1', 456 => 'Value 2', 789 => 'Value 3')
其中数字是给定的ID。要获得默认值,请执行以下操作:
$choices_branches = array_merge(array('default' => 'Bitte wählen'), $branches);
$this->setWidgets(array(
'branches' => new sfWidgetFormChoice(array(
'choices' => $choices_branches,
'expanded' => false,
)),
...))
在form类中,我执行以下操作:
$choices_branches = array_merge(array('default' => 'Bitte wählen'), $branches);
$this->setWidgets(array(
'branches' => new sfWidgetFormChoice(array(
'choices' => $choices_branches,
'expanded' => false,
)),
...))
这是验证器:
$this->setValidators(array(
'branches' => new sfValidatorChoice(array('choices' => array_keys($branches))),
...
))
但当我选择例如值1并尝试提交表单时,我得到一个无效错误
有人能帮忙吗?来自
不要忘记数字键将被重新编号
您应该执行以下操作:
$choices = array(123 => 'Value 1', 456 => 'Value 2', 789 => 'Value 3');
$this->setWidget('branches', new sfWidgetFormChoice(array(
'choices' => array('' => 'Bitte wählen') + $choices,
'expanded' => false,
));
$this->setValidator('branches', new sfValidatorChoice(array(
'choices' => array_keys($choices),
));