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

2

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

Queeniequeenly answered 22/2, 2012 at 14:25 Comment(0)
S
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.

Sorayasorb answered 22/2, 2012 at 14:32 Comment(2)
Wasn't aware of this. Removed my answer.Lute
link is dead :( but I'm using ZF2 nowBoren
E
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>
Exsiccate answered 22/2, 2012 at 14:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.