Zend形式:显示单选框具有正确值时的元素

| 我正在忙于一个基于zend框架的新项目。我创建了以下表格:
<?php
class Application_Form_User extends Zend_Form
{

    public function init()
    {
       $this->setMethod(\'post\');
       $this->setAttrib(\'class\',\'zf\');
       $this->addElement(\'text\', \'username\', array(
        \'label\' => \'Gebruikersnaam:\',
        \'required\' => true,
        \'filters\' => array(\'StringTrim\'),
        \'validators\'=>array(
                array(\'Db_NoRecordExists\',
                false,
                array(
                    \'table\'=>\'user\',
                    \'field\'=>\'username\'
                )
            ))
       ));
       $this->addElement(\'text\', \'name\', array(
        \'label\' => \'Volledige naam:\',
        \'required\' => true,
        \'filters\' => array(\'StringTrim\'),
       ));
       $this->addElement(\'text\', \'email\', array(
        \'label\' => \'Email:\',
        \'required\' => true,
        \'filters\' => array(\'StringTrim\'),
        \'validators\'=>array(
            \'EmailAddress\',
            array(
                \'Db_NoRecordExists\',
                false,
                array(
                    \'table\'=>\'user\',
                    \'field\'=>\'email\'
                )
            )
        )
       ));
       $this->addElement(\'password\', \'password1\', array(
        \'label\' => \'Wachtwoord:\',
        \'required\' => true,
        \'filters\' => array(\'StringTrim\'),
       ));
       $this->addElement(\'password\', \'password2\', array(
        \'label\' => \'Wachtwoord (controle):\',
        \'required\' => true,
        \'filters\' => array(\'StringTrim\'),
        \'validators\'=>array(array(\'Identical\',false,\'password1\'))
       ));
       $this->addElement(\'radio\',\'type\',array(
            \'label\'=>\'Gebruikers type:\',
            \'required\'=>true,
            \'multiOptions\'=>array(
                \'consumer\'=>\'Klant\',
                \'admin\'=>\'Beheerder\'
            )   
        ));
       $this->addElement(\'text\', \'mobile\', array(
        \'label\' => \'Mobiel:\',
        \'required\' => true,
        \'filters\' => array(\'StringTrim\'),
       ));
        $this->addElement(\'textarea\', \'address\', array(
        \'label\' => \'Address:\',
        \'required\' => true,
        \'style\'=>\'width: 200px;height: 100px;\'
       ));

       $this->addElement(\'submit\', \'submit\', array(
        \'ignore\'=>true,
        \'label\'=>\'Toevoegen\'
       ));
       $this->addElement(\'hash\', \'csrf\', array(
            \'ignore\' => true,
        ));

    }
}
此表单具有一个单选按钮,其值为\'Consumer \'和\'Admin \'。我想要的是,当该值为\'Consumer \'时,将显示一些额外的字段,而当值为\'admin \'时,将显示其他元素。 因此,当值为“消费者”时,我想例如以下字段:消费者ID,消费者kvk号。当用户切换到管理单选按钮时,此字段必须消失。(因此必须为JS) 有没有一种方法可以在Zend Form中直接使用?还是我必须制作自己的HTML表单? 汤姆     
已邀请:
        您可以进行如下操作:
public function init($data = false)
{
   if (isset($data[\'type\']) && $data[\'type\'] == \'consumer\') {
      // add element or hide element
   }
}
在控制器中,您可以获取表格数据并将其传递给表格“ 2”;     

要回复问题请先登录注册