Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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...

like image 442
Rajan Rawal Avatar asked Feb 22 '12 14:02

Rajan Rawal


2 Answers

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.

like image 150
markus Avatar answered Sep 20 '22 10:09

markus


You can either use setOrder()as markus said, or when you render your form in your viewscript, you can render 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>
like image 32
Liyali Avatar answered Sep 19 '22 10:09

Liyali