I have created a form like this:
class Form_Login extends Zend_Form {
public function __construct() {
$this->setMethod('post');
$elements = array();
// username
$element = $this->addElement('text', 'username', array('label' => 'Username') );
$elements[] = $element;
// password
$element = $this->addElement('password', 'password', array('label' => 'Password'));
$elements[] = $element;
// submit
$element = $this->addElement('submit', 'submit', array('label' => 'Login'));
$elements[] = $element;
$this->addElements( $elements );
$this->addDecorator('ViewHelper');
$this->setDecorators(array(array('ViewScript', array('viewScript' => 'authentication/login-form.phtml' ))));
}
}
Now in login-form.phtml file I render elements like this:
<form action='submitlogin' method='post' id='loginform'>
Login Form
<?= $this->form->getElement('username'); ?>
<?= $this->form->getElement('password'); ?>
</form>
It gives me following error:
Fatal error: Call to a member function getElement() on a non-object in
/var/www/student/application/views/scripts/authentication/login-form.phtml on line 5
How to render elements in external script…
You can call elements from the view scripts like this:
For specific element components you can use the next things: