Zend Framework Tutorial Zend_form component implement form submission and display Error prompt method, zendzend_form_php tutorial

Source: Internet
Author: User
Tags valid email address zend framework

The Zend_form component of the Zend framework tutorial implements the way the form submits and displays the error prompt, Zendzend_form


The examples in this article describe how the Zend_form component of the Zend Framework tutorial implements form submission and displays error hints. Share to everyone for your reference, as follows:

At the same time the company also developed a group function. I also want to use the Zend_form to implement the function of creating a group. The main or fancy zend_form can be in writing form. Implement server-side validation capabilities. It saves us the time to validate the data when it is submitted to the database. So, I just read the manual on this. Relevant usage notes were found through the Zend Framework manual ... The simplest way to use this is to write a ready-made action in the controller, so: You can use this action directly in this controller ... The code can be as follows:

<?phppublic function FormAction () {$form =new zend_form (); $form->setname (' group '); $title = New Zend_form_element_select (' title '), $title->setlabel (' Gender ')->setmultioptions (' Mr ' = ' Mr ', ' mrs ' = > ' Mrs '))->setrequired (True)->addvalidator (' Notempty ', true); $yourName = new Zend_form_element_text (' FirstName '); $yourName->setlabel (' name ')->setrequired (True)->addvalidator (' Notempty ', true); $email = new Zend_form_element_text (' email '), $email->setlabel (' E-mail address ')->addfilter (' Stringtolower ')->setrequired ( False)->addvalidator (' Notempty '); $submit = new Zend_form_element_submit (' submit '); $submit->setlabel (' group ' ); $form->addelements (Array ($title, $yourName, $email, $submit));}? 

Of course.. I can also write this form specifically as a class ... stored in a common directory of forms. This allows us to manage all of our form forms. My implementation is to put it in the same level directory as the controller. This is also convenient to manage. Of course different friends. have different ideas ... Another way: It is possible to write it as a view Helper ... This way is realized, and also very convenient. I don't want to write more here ... The Zend framework is easy to implement ... As long as you want to ... No matter how you accomplish your task, it is all possible. I'm not going to say anything else here. I just want to talk about how to get zend_form to implement the Chinese information function ... I have two ways to do it here.

First: The more stupid way is: If your website does not make multi-lingual website. At the same time your Zend Framework version is not frequently replaced ... You can find the source of the relevant information ... The prompt to change into Chinese.

This stupid method. There is no way to do it ... Oh...

Second: I am also in English station ... A better way to see this is by rewriting the message. Replace it with the language we want ... So ... Even if we're going to change the language. or change the version of the Zend Framework:

The impact on us is not very big ... We just need to change the form of our forms to get it done. Now the code for this way is as follows (I just wrote the email message here.) Others do not write more):

<?php$email = new Zend_form_element_text (' email '), $email->setlabel (' E-mail address ')->addfilter (' Stringtolower ') ->setrequired (False)->addvalidator (' Notempty ')->addvalidator (' EmailAddress ', True,array (' Messages ' = > Array (' emailaddressinvalid ' = ' This is not an available email! ', ' emailaddressinvalidhostname ' = ' This is not a valid hostname! ') ' Emailaddressinvalidmxrecord ' = ' This is not a valid email address! ', ' emailaddressdotatom ' = ' This is not a valid email address! ', ' Emailaddressquotedstring ' = ' This is not a valid email address! ', ' emailaddressinvalidlocalpart ' = ' This is not a valid email address! ', ');?>

to here. Zend_form This component also has a more important function. Is Zend_form_decorator. The manual is called an adorner, which means you can write the adorner you want. For example.. You have to include your form with table. How are we going to achieve this? We're going to use these decorators like Htmltag,label to get the features we want ... Here is a more important concept. Interested friends can go to have a look ... Because if you want to use zend_form this component: No adorners are difficult to use. So it has to be this thing. Before you can create the form features you want: At last.. It's just a little bit of a decorator's use.

I just realized a little function ... The following code:

<?php$email = new Zend_form_element_text (' email '), $email->setlabel (' E-mail address ')->addfilter (' Stringtolower ') ->setrequired (FALSE)//use adorner to add TD label->adddecorator (' Htmltag ', array (' tag ' = ' TD '))->adddecorator (' Label ', array (' tag ' = ' TD ')///re-use the Htmltag adorner to increase the TR label->adddecorator (' footr ' = ' Htmltag '), array (' tag ' = ' tr '))->addvalidator (' Notempty ');? >

Ha ha.... The general application is this ... At last.. is to validate the submitted data ... See how to verify the data submitted by the user .... There's not much to say ... Ok...

More interested in Zend related content readers can view the topic: "Zend framework of the introductory tutorial", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Tutorial", "PHP object-oriented Programming introduction tutorial "," Introduction to Php+mysql Database Operation "and" PHP common database Operation Skills Summary "

It is hoped that this article will help you to design PHP based on the Zend Framework framework.

Articles you may be interested in:

    • Zend Framework Framework Tutorial Zend_db_table_rowset Usage Example Analysis
    • Zend Framework Tutorial Zend_db_table_row Usage Example Analysis
    • Zend Framework Tutorial Zend_db_table Usage
    • Introduction to Zend Framework Development Classic Tutorial
    • Zend Framework Smarty Extension Implementation method
    • Code analysis of routing mechanism of Zend framework framework
    • Zend Framework implementation of basic functions of the message book (with demo source download)
    • The Zend framework implements the method of storing the session in Memcache
    • Zend Framework Paging Class usage
    • Zend Framework implements multi-file upload function instances
    • Zend Framework Introduction Environment configuration and the first Hello World example (with demo source download)
    • Zend Framework Tutorial to connect the database and perform additions and deletions of the method (attached to the demo source download)
    • Zend Framework Tutorial Zend_db_table Table Association Instance detailed

http://www.bkjia.com/PHPjc/1113736.html www.bkjia.com true http://www.bkjia.com/PHPjc/1113736.html techarticle The zend_form component of the Zend framework Tutorial implements the form submission and displays the error prompt method, Zendzend_form This article describes the Zend Framework tutorial Zend_form component Implementation form submission and ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.