Symfony自定义表单验证器以获取一定数量的选项

时间:2012-10-19 20:32:02

标签: forms symfony-1.4 validation

我有一个包含以下小部件和验证器的表单:

  $this->widgetSchema['num01'] = new sfWidgetFormChoice(array(
  'choices' => Doctrine_Core::getTable('ticket')->getTicketnum(),
  'expanded' => true, 'multiple' => true,
   ));

  $this->validatorSchema['num01'] = new sfValidatorChoice(array(
   'choices' =>
   array_keys(Doctrine_Core::getTable('ticket')->getTicketnum()), 'required' => true, 'multiple' => true,
   ));

我遇到的问题是它显示了20个复选框,我想让它们只选择其中的5个。不多也不少。它必须正好检查5盒。如何自定义我的代码以使其以这种方式验证?感谢

1 个答案:

答案 0 :(得分:0)

我试过这只是为了看看它是否会起作用。 :)

$this->validatorSchema['num01'] = new sfValidatorChoice(array(
   'choices' =>
   array_keys(Doctrine_Core::getTable('ticket')->getTicketnum()), 'required' => true,
   'multiple' => true, 'max' => 5, 'min' => 5,
   ));