Create a Form

For our guestbook to be useful, we need a form for submitting new entries.
Our first order of business is to create the actual form class. First, create the directory application/forms/. This directory will contain form classes for the application. Next, we'll create a form class in application/forms/Guestbook.php:
<?php

 Default_Form_Guestbook  Zend_Form
{
      init()
    {
        
        $this->setMethod();
        
        $this->addElement(, , (
                  => ,
               => true,
                => (),
             => (
                ,
            )
        ));
        
        $this->addElement(, , (
                  => ,
               => true,
             => (
                ( => ,  => (, ))
                )
        ));
        
        $this->addElement(, , (
                  => ,
               => true,
                => (
                 => , 
                 => , 
                 => 
            )
        ));
        
        $this->addElement(, , (
               => true,
                => ,
        ));
        
        $this->addElement(, , (
             => true,
        ));
    }
}
The above form defines five elements: an email address field, a comment field, a CAPTCHA for preventing spam submissions, a submit button, and a CSRF protection token.
Next, we will add a signAction() to our GuestbookController which will process the form upon submission. To create the action and related view script, execute the following:

% zf.sh create action sign guestbook

C:> zf.bat create action sign guestbook
This will create a signAction() method in our controller, as well as the appropriate view script.
Let's add some logic into our guestbook controller's sign action. We need to first check if we're getting a POST or a GET request; in the latter case, we'll simply display the form. However, if we get a POST request, we'll want to validate the posted data against our form, and, if valid, create a new entry and save it. The logic might look like this:
<?php

 GuestbookController  Zend_Controller_Action
{
    
      signAction()
    {
        $request = $this->getRequest();
        $form    =  Default_Form_Guestbook();
         ($this->getRequest()->isPost()) {
             ($form->isValid($request->getPost())) {
                $model =  Default_Model_Guestbook($form->getValues());
                $model->save();
                 $this->_helper->redirector();
            }
        }
        
        $this->view->form = $form;
    }
}
Of course, we also need to edit the view script; edit application/views/scripts/guestbook/sign.phtml to read:
<!-- application/views/scripts/guestbook/sign.phtml -->
Please  the form below to sign our guestbook!
<?php 
$this->form->setAction($this->url());
 $this->form;
Better Looking Forms
No one will be waxing poetic about the beauty of this form anytime soon. No matter- form appearance is fully customizable! See the decorators section in the reference guide for details.
Additionally, you may be interested in this series of posts on decorators.
Checkpoint
Now browse to http://localhost/guestbook/sign. You should see the following in your browser:
GuestbookForm.png