I’m working on a small php application using Zend Framework. I created a form using Zend_Form but when I try to display it in the browser, it’s not working properly.
Here is my Form class:
class IndexForm extends Zend_Form {
public function init(){
$this->setAction('main/main');
$this->setMethod('post');
$username = $this->addElement('text','uname',array('filters'=>array('StringTrim','StringToLower'),
'validators'=>array('Alpha',
array('StringLength',false,array(3,20)),
),
'required'=>true,
'label'=>'User Name:'));
$password = $this->addElement('password','pwd',array('filters'=>array('StringTrim'),
'validtors'=>array('Alnum',
array('StringLength',false,array(6,20)),),
'required'=>true,
'label'=>'Password:'
));
$login = $this->addElement('submit', 'login', array(
'required' => false,
'ignore' => true,
'label' => 'Login',
));
}
}
?>
Here is my IndexController.php
<?php
class IndexController extends Zend_Controller_Action {
public function init() {
/*
* Initialize action controller here
*/
}
public function indexAction() {
include APPLICATION_PATH.'/models/Forms/IndexForm.php';
$form = new IndexForm();
$this->view->form = $form;
}
}
Here is my index.phtml, where I need to display the form.
<html>
<style>
</style>
<body><br>
<img alt="" src="http://localhost/Accounts/application/views/scripts/images/logo.png" width=200px height=80px><!-- see whether you can get the host name dynamically -->
<div id="text" >
<h1>Welcome</h1><br><hr>
<h4>Please Log in To View The Main Page</h4></div>
<?=$this->form?> <!--here I want to display the form-->
<div><?php include APPLICATION_PATH.'/views/scripts/layouts/footer.php';?>
</div>
</body>
</html>
The output I get instead of the form is form?>.
Why is this? what’s wrong in my codes? Please help me.
Thanks in advance
Charu
First Try
If this works, then you have short tags disabled. Enable it using