Analysis of how to create a FORM form under zend Farmework_PHP tutorial

WBOY
Release: 2016-07-21 15:02:08
Original
1503 people have browsed it

1. First, let us set up our program so that Zend can automatically load the method without us having to manually load it

Copy code The code is as follows:

require_once 'Zend/Loader/Autoloader.php' //Load the autoloading class
$loader = Zend_Loader_Autoloader::getInstance();//Automatic instantiation
$loader->registerNamespace('Application_');//Register namespace (only the system default and registered ones can be automatically loaded)
$loader->registerNamespace(array('Foo_ ', 'Bar_')); //Registration method for multiple namespaces
$loader->setFallbackAutoloader(true); //A method to increase consumption, no namespace is required, and all classes are loaded directly (no Recommended)

Then please pay attention to whether your include directory has been included, and your own directory that needs to be loaded
Copy code The code is as follows:

set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/ forms/'),
get_include_path(),
)));
//Here we include our forms directory to facilitate the loading of the program

2. Confirm the directory of the form
Create a Guestbook.phps
under application/forms/ as the class file of our form, as follows:
Copy Code The code is as follows:

class Application_Form_Guestbook extends Zend_Form
{
public function init()
{
// Set the method for the display form to POST
$this->setMethod('post');//Set submission method

                                                                                                                                                               / Definition of original type, noun, and some other information
        'label'                                                                                                                       ('StringTrim'),
'validators' => array(
'EmailAddress',
)
));

// Add the comment element
          $ this->addElement('textarea', 'comment', array(
'label' => 'Please Comment:',
'required' => true,
'validators' => ; array(
                           array('validator' => a captcha
$this->addElement('captcha', 'captcha', array(
'label' => 'Please enter the 5 letters displayed below:',
'required' => ; true,
'captcha' => array(
'captcha' => 'Figlet',
'wordLen' => 5,
'timeout' => 300
            )
         ); ,
                                                                                                                                                                                      'Sign Guestbook', csrf', array(
         'ignore' => true,
          )); controller/GuestbookController.php



Copy code

The code is as follows:

class GuestbookController extends Zend_Controller_Action
{
// snipping indexAction()...
public function signAction()
{
$request = $this->getRequest(); //Get the received information
// include_once("../application/forms/Guestbook.php"); Manually load the class, only when it cannot be loaded automatically. Need
$form = new Application_Form_Guestbook;//Instantiate this method

if ($this->getRequest()->isPost()) {//If it is the result of POST delivery
                                                                                                                                                                                             mapper = new Application_Model_GuestbookMapper();
$mapper->save($comment);
return $this->_helper->redirector('index');
}
}

$this->view->form = $form;//Assign the form to the view
}
}


Finally add a simple The sign view file can be:
Address: application/views/scripts/guestbook/sgin.php

Copy code The code is as follows:
Please use the form below to sign our guestbook!
$this->form->setAction($this->url());
echo $this->form;



http://www.bkjia.com/PHPjc/327948.html

truehttp: //www.bkjia.com/PHPjc/327948.htmlTechArticle1. First, let us set up our program so that Zend can automatically load methods without us manually To load the copied code, the code is as follows: require_once 'Zend/Loader/Autoloader.p...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template