一千萬個為什麽

搜索

Zend Form如何對這樣的元素進行分組?

我創造了一個zend形式。我想制作一組輸出html的元素:

           <div class="form_wrapper">
                <div class="form_label">
                    
                    *
                </div>
                <div class="form_element">
                    
                    <input type="text" id="salary_min" class="txtinput" name="salary_min" value="Min" onfocus="if(this.value=='Min') this.value='';" onblur="if(this.value=='') this.value=('Min');">
                    <input type="text" id="salary_max" class="txtinput" name="salary_max"  value="Max" onfocus="if(this.value=='Max') this.value='';" onblur="if(this.value=='') this.value=('Max');">
                </div>
            </div> <!-- end .form_wrapper -->

我的代碼:

 $this->addElement('select', 'salary_type', array(
            'label' => 'Salary type',
            'multiOptions' => $salary_types,
            'class'=>'jp_select'
        ));

        $this->addElement('text', 'salary_min', array(
            'label' => 'Min',
            'class'=>'txtinput'
        ));

        $this->addElement('text', 'salary_max', array(
            'label' => 'Max',
            'class'=>'txtinput'
        ));

$this->addDisplayGroup(array('salary_type','salary_min','salary_max'), 'salary_group');

如何設置裝飾器以具有如上所述的html輸出

最佳答案

As far as I know, you are not able to render that exact html structure with simple Decorators alone. One way to solve this problem is by using the ViewScript Decorator within your displayGroup decorator stack. Within the view script, you are able to retrieve the individual elements by using $this->element->getElements(); ($this->element is an instance of Zend_Form_DisplayGroup)

例如:

$this->addDisplayGroup(
    array('salary_type','salary_min','salary_max'), 
    'salary_group',
    array(
        'decorators' => array(
            array('ViewScript', array('viewScript' => 'path/to/viewscript.phtml')),
        ),
    )
);

沒有自己試過,但它應該工作。

轉載註明原文: Zend Form如何對這樣的元素進行分組?