单击隐藏/显示单击单击按钮使用Zend表单

时间:2013-06-02 06:27:33

标签: zend-framework zend-form

这是我的代码:

class File_Form_AddFile扩展了Custom_Form {

public function init() {

    $translate = Zend_Registry::get('translate');
    $this->setTranslator($translate);
    $this->setName("addfile");
    $this->setMethod('post');


    $this->addElement('text', 'title', array(
        'filters' => array('StringTrim'),
        'validators' => array(
            array('StringLength', false, array(0, 50)),
        ),
        'required' => true,
        'label' => __('Title') . ':',
    ));


    $this->addElement('radio', 'type', array(
        'label'=>__('Applicant Type'),
        'multiOptions' => array(
            'office' => 'Office',
            'community' => 'Community',
            'person' => 'Person',
        ),
        'required' => true,
        'separator' => '',
        'value' => 'office'
    ));


    **// I want this section to show only after 'community' is clicked at above input field.**

    $this->addElement('radio', 'community_is_registered', array(
        'label'=>__('Registered Community?'),
        'multiOptions' => array(
            1 => 'Yes',
            0 => 'No',
        ),
        'separator' => '',
        'value' =>'0'
    ));


    $this->addElement('text', 'name', array(
        'filters' => array('StringTrim'),
        'validators' => array(
            array('StringLength', false, array(0, 100)),
        ),
        'required' => true,
        'label' => __('Applicant Name') . ':',
    ));



    $this->addElement('submit', 'save', array(
        'required' => false,
        'ignore' => true,
        'label' => __('Save'),
    ));
    $this->save->removeDecorator('label');
}

}

这是一个添加文件信息的表单。在这里,我想展示“注册社区”部分?只有在“申请人类型”中单击“社区”按钮后。寻求帮助!!

1 个答案:

答案 0 :(得分:0)

由于您希望在客户端基于客户端发生的某些操作在客户端发生某些行为,因此它似乎从根本上是客户端问题。

也许最简单的事情是:

  1. 在服务器端表单创建期间,将某个CSS类添加到Registered Community元素(或显示组,如果它是元素集合)。

  2. 使用前端CSS隐藏该类的所有表单元素。

  3. 向“申请人类型”元素添加客户端点击处理程序,当“申请人类型”具有所需值时,该元素会删除/更改类或显示/隐藏“注册社区”部分。< / p>

相关问题