7

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

Rajan Rawal
  • 6,171
  • 6
  • 40
  • 62

2 Answers2

14

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.

markus
  • 40,136
  • 23
  • 97
  • 142
6

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>
Liyali
  • 5,643
  • 2
  • 26
  • 40