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:

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

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:'));
$this->addElement($text1);
$select1=new Zend_Form_Element_Select('animal_group',
              array('label'=>'Select group of animal:',
                    'multiOptions'=>array('mammals'=>'Mammals','reptiles'=>'Reptiles')));
$this->addElement($select1);
$submit1=new Zend_Form_Element_Submit('animal_submit',array('label'=>'Send data'));
$this->addElement$submit1);

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:

form14

One thought on “Creating form in Zend Framework in Netbeans IDE

  1. Ed Sowell

    I installed PHP 7 and Zend Framework 1.34.1 in NetBeans 8.2 and tried to create a simple form. However, when I get to the 4th step the PHP Framworks box is empty… no list of Framworks to choose from. Any idea what I might be doing wrong?

    Reply

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.