Creating form in Zend Framework in Netbeans IDE

My another work in Zend Framework is forms. In this post I show You how creating form with several form elements.
Begin with open Netbeans IDE and selecting from main menu File->New Project.

zoo00In New Project window in Categories section select PHP and in Projects section select PHP Application and click on Next button.

zoo1In Project Name field write MyForm. It is your project’s name.  Click on Next button.

form01In another step in Project URL field add to the end of path word public. Click on Next button.

form03From list of PHP Frameworks select Zend PHP Web Framework and click on Finish button.

zoo04In Projects window in Netbeans, You see structure of Your project.

form04Open .htaccess file from public node and paste into it on the top this code:

SetEnv APPLICATION_ENV development
DirectoryIndex index.php

form05Owing to You may display errors information in displaying websites. Save this file and right click on project node and select Zend->Run Command.

form06In Run Zend window write in Filter field enable layout and click on Run button.

form07From application/layouts/scripts open layout.phtml file. Paste into it this code:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
    <?php echo $this->layout()->content; ?>    

form08In this moment You may create form. Right click on project node and choose Zend->Run Command.

form06In Run Zend window in Filter field write create form and in Parameters field write name of form: My. Click on Run button.

form09Open new creating file in applications/forms node(My.php).

form10Paste into it in init method this code:

$text1=new Zend_Form_Element_Text('animal_name',array('label'=>'Animal name:'));
$select1=new Zend_Form_Element_Select('animal_group',
              array('label'=>'Select group of animal:',
$submit1=new Zend_Form_Element_Submit('animal_submit',array('label'=>'Send data'));

Save My.php file.

form11Open in application/controllers node indexController.php file. Paste into indexAction method code:

 $this->view->form = new Application_Form_My();

form12Save file.

Open view for form( file index.phtml in application/views/scripts/index node ).

Paste into this file code:

<h3>My form</h3>
<?php echo $this->form; ?>

form13If You call only form variable for current object You see all form. Run application and see result:


Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.