How to add a zend form element to a specific position after a form object has already been created?

I created one user_form class that extends the zend form, it has 4 usernames, a password, a hash for csrf, and finally a submit button.

Creating a user_form object displays all of these four elements.

After checking the controller’s entry into the action, I check for failure attempts, and after a number of bug fixes, I want to add a zend captch in front of the submit button.

I added the captcha element and added it after the submit button.

How to add a zend element to a specific position? Or how can I add it before sending?

Also let me know that the way I'm doing is the right one? Waiting for your reply. Thanks...

+7
source share
2 answers

Give your items serial numbers from the start. Add the order number to the captcha element when you add it.

$element->setOrder(10); 

or

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

See also Zend_Form Guide .

+14
source

You can use setOrder() , as Marcus said, or when you render your form in your viewcript, you can display each field separately:

 // .phtml <form id="form" action="<?= $this->escape($this->form->getAction()); ?>" method="<?= $this->escape($this->form->getMethod()); ?>"> <table> <?= $this->form->username ?> <?= $this->form->password ?> <?= $this->form->hash ?> <?= $this->form->captcha ?> <?= $this->form->submit ?> </table> </form> 
+6
source

All Articles