After adding elements to my form, I get them rendered in a weird order, getting the submit button before one checkbox. Would appreciate hints on where to check for a quick fix.
class SomeForm extends My_Form {
public function init() {
$this->addElements();
//add a few elements (#1)
$this->addElements($otherForm->getElements());
//borrow some elements from another form (#2)
if ($trueCondition=true) {
$this->addElements();
//add one more element which will render at end of form (#3)
}
$this->addElements();
//some more, including submit button (#4)
parent::init();
//call My_Form to register custom decorator; culprit?
}
}
Output:
<inputs from addElements() #1 />
<inputs from addElements() #2 />
<inputs from addElements() #4 /> <-
<inputs from addElements() #3 /> <- mixed up order
All other forms using the custom decorator render elements in the order that they were added. I’m not posting the decorator as it’s pretty messy. Hopefully the error lies elsewhere.
I tried to reproduce your problem using this code:-
Which gave me this output (decorators removed)
Which is what you are expecting. The only way to reproduce your problem was by setting the order of an element in
$formBWhich gave me this output
Which is what you are getting. So, it seems to me that you must be setting the order of elements in
$otherForm.