Mobile-Menu iFuturz Infoweb Inc. Contact Portfolio

11

Sep

How to make form in ZEND Framework

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

Posted On : September 11, 2013

| 2 Comments

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()
	{
 
 
		$this->setName('contact');
 
		$id = new Zend_Form_Element_Hidden('id');
		$id->addFilter('Int');
 
		$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');
		$password->setLabel('Password:');
 
		$address = new Zend_Form_Element_Textarea('address');
		$address->setLabel('Address:')
		          ->setAttrib('cols', '30')
				  ->setAttrib('rows', '4');
 
 
 
		 $city = new Zend_Form_Element_Select("city");
    $city->setLabel("city")  
         ->setName("city");
 
    $city->addMultiOption('ahmedabad','ahmedabad');
    $city->addMultiOption('barda','baroda');
    $city->addMultiOption('surat','surat');
    $city->addMultiOption('kutch','kutch');
 
 
 
	    $hobby = new Zend_Form_Element_Text('hobby');
		$hobby->setLabel('hobby:');
 
 
 
		$this->addElement ('img', 'myimage', array (
        'src'           =>'http://192.168.1.134/zend_project/application/images/profileNoPicMale.png',
        '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:

Comment

Posts

  • 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 =)

    Nicole

    • Thankyou Nicole for your support.

      iFuturz