我尝试使用此代码重现您的问题:-
$formA = new Zend_Form();
$formB = new Zend_Form();
$formA->addElement(new Zend_Form_Element_Text('formA_text1'));
$formA->addElement(new Zend_Form_Element_Text('formA_text2'));
$formB->addElement(new Zend_Form_Element_Text('formB_text1'));
$formB->addElement(new Zend_Form_Element_Text('formB_text2'));
$formA->addElements($formB->getElements());
$formA->addElement(new Zend_Form_Element_Text('formA_text3'));
$formA->addElement(new Zend_Form_Element_Submit('submit'));
echo $formA->render();
这给了我这个输出(移除了装饰器)
<input type="text" name="formA_text1" id="formA_text1" value="">
<input type="text" name="formA_text2" id="formA_text2" value="">
<input type="text" name="formB_text1" id="formB_text1" value="">
<input type="text" name="formB_text2" id="formB_text2" value="">
<input type="text" name="formA_text3" id="formA_text3" value="">
<input type="submit" name="submit" id="submit" value="submit">
这是你所期待的。重现问题的唯一方法是设置元素的顺序$formB
$formA = new Zend_Form();
$formB = new Zend_Form();
$formA->addElement(new Zend_Form_Element_Text('formA_text1'));
$formA->addElement(new Zend_Form_Element_Text('formA_text2'));
$formB->addElement(new Zend_Form_Element_Text('formB_text1'));
$formB->addElement(new Zend_Form_Element_Text('formB_text2'));
$formB->getElement('formB_text2')->setOrder(10);
$formA->addElements($formB->getElements());
$formA->addElement(new Zend_Form_Element_Text('formA_text3'));
$formA->addElement(new Zend_Form_Element_Submit('submit'));
echo $formA->render();
这给了我这个输出
<input type="text" name="formA_text1" id="formA_text1" value="">
<input type="text" name="formA_text2" id="formA_text2" value="">
<input type="text" name="formB_text1" id="formB_text1" value="">
<input type="text" name="formA_text3" id="formA_text3" value="">
<input type="submit" name="submit" id="submit" value="submit">
<input type="text" name="formB_text2" id="formB_text2" value="">
这就是你得到的。因此,在我看来,您必须在$otherForm
.