How to add zend form element at specific position, after once form object has already created?

Rajan Rawal picture Rajan Rawal · Feb 22, 2012 · Viewed 7.8k times · Source

I have created one user_form class that extends zend form, it has 4 elements username, password, hash for csrf and at last submit button.

Creating object of user_form renders all those four element.

After validating login in controller action i checks fail attempts, and after some fix number of fail attempts I want to add zend captch before submit button.

I added captcha element and it was appended at after submit button.

How can I add zend element at specific position? Or How can i add it before submit button?

Also let me know that the way am I doing is proper? Waiting for your reply. Thank you...

Answer

markus picture markus · Feb 22, 2012

Give your elements order numbers from the very begining. Add an order number to the captcha element, when you add it.

$element->setOrder(10);

or

$form->addElement('text', 'username', array('order' => 10));

See also the Zend_Form manual.