Mobile-Menu iFuturz Infoweb Inc. Contact Portfolio



How to make form in ZEND Framework

  • Category:
  • PHP
How to make form in ZEND  Framework

Posted On : September 11, 2013


Anyone can create form in Zend framework by following steps

Zend Framework follow as MVC Framework (MODEL-VIEW-CONTROLLER) . So need to create three folder as per MVC structure

Step-1 :- Go on your this path:- zend_(project_name) application.

Step-2 : Make new Folder name of form.

Step-3 :- create new Php file and Put this below Code which are make form.

class Application_Form_contact extends Zend_Form
	public function init()
		$id = new Zend_Form_Element_Hidden('id');
		$first_name = new Zend_Form_Element_Text('first_name');
		$first_name->setLabel('First name:');
        $last_name = new Zend_Form_Element_Text('last_name');
		$last_name->setLabel('Last name:');
		$email_id = new Zend_Form_Element_Text('email_id');
		$email_id->setLabel('Email Id:')
				 ->addValidator('EmailAddress',  TRUE  );
		$password = new Zend_Form_Element_Password('password');
		$address = new Zend_Form_Element_Textarea('address');
		          ->setAttrib('cols', '30')
				  ->setAttrib('rows', '4');
		 $city = new Zend_Form_Element_Select("city");
	    $hobby = new Zend_Form_Element_Text('hobby');
		$this->addElement ('img', 'myimage', array (
        'src'           =>'',
        'align'         => 'left',
		$submit = new Zend_Form_Element_Submit('submit');
		$submit->setAttrib('id', 'submit');
		$this->addElements(array($id, $first_name, $last_name, $email_id, $password,$address,$city,$hobby,$submit));

Step:4:- Now, Go to on this path:- application\views and Make folder name of view folder Name which are Your VIEW part and make new index.phtml file in this folder

Step:5:- Put this below code in index.phtml file.

<div class="form"> <?php echo $this->form; ?></div>

Step:6-:Now, Go to on This Path: application\controllers and make controller file.

Step:7:- Put on below code in Controller file.

class ContactController extends Zend_Controller_Action
{	public function init()
    {      /* Initialize action controller here */
public function indexAction()
	   $form = new Application_Form_contact();
	    $this->view->form = $form;

you will get following screen layout

  • Tags:



  • Wonderful article! This is the kind of info that are supposed to be shared around the web.
    Disgrace on the search engines for now not positioning this
    post higher!
    Thank you =)


    • Thankyou Nicole for your support.