Zend Form Tutorial

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

7 comments

Comments 1 - 7 of 7 previous next Post a comment

  • + guest624635 guest624635 6 months ago
    looks good
  • + guestcbc7e21 guestcbc7e21 7 months ago
    I agree, it’s stupid to store your forms as xml... You will find many problems later on since clients tend to want things changed all the time...
  • + cistyblazon cistyblazon 8 months ago
    Oh that’s great idea -> generate form’s from xml,
    Thank you for your tutorial
  • + guest09d309 guest09d309 8 months ago
    How does one put a textbox along with its labelrather than below its label?
  • + guest9a036a guest9a036a 2 years ago
    boring, storing ur forms as xml is lame and static also. try php class models
  • + DragonBe Michelangelo van Dam 2 years ago
    In slide 6 I said it was for Zend Framework 1.5 and higher, this means that you need to verify (Zend/Version.php) if you’re using the right version.

    If this is the case, walk through my list of questions here:
    - is the location of your Zend Framework library set in the include path ?
    - Have you set a 'require_once ’Zend/From.php’ or you have it autoloaded ?
    - Are you working on multiple servers (for load balancing) ?

    Try to answer these questions to see if something is missing. If you still can’t find a solution to it, contact me using the e-mail mentioned on slide 2.

    Cheers,

    Michelangelo
  • + guest5ce526 guest5ce526 2 years ago
    hmmm seems ok...but when i m trying i can’t find Zend_Form class...:(

    http://apexvideo.blogspot.com
Post a comment
Embed Video
Edit your comment Cancel

6 Favorites

Zend Form Tutorial - Presentation Transcript

  1. Zend_Form tutorial by Michelangelo van Dam
  2. Who is Michelangelo van Dam ?
    • Freelance PHP consultant with over 7 years of enterprise level PHP development experience.
    • Started using Zend Framework in 2007 and contributes to this framework for Zend_Ldap.
    • web: http://www.in2it.be
    • blog: http://dragonbe.blogspot.com
    • e-mail: dragonbe [at] google mail
  3. Zend_Form
    • Zend_Form simplifies form creation and handling in your web application. It accomplishes the following goals:
    • Element input filtering and validation
    • Element ordering
    • Element and Form rendering, including escaping
    • Element and form grouping
    • Element and form-level configuration
  4. Zend_Form (continued)
    • It heavily leverages other Zend Framework components to accomplish its goals, including Zend_Config, Zend_Validate, Zend_Filter, Zend_Loader_PluginLoader, and optionally Zend_View.
    • More info can be found at http://framework.zend.com/manual/en/zend.form.html
  5. Directory structure
    • application_root/
      • application/
        • config/ -> this is where you put the configuration files
          • userform.xml
        • controllers/ -> this is where you put your controllers
          • UserController.php
        • views/ -> this is where you put your view templates
          • user/
            • login.phtml, register.phtml, resetpassword.phtml
      • web/
        • index.php -> your bootstrap file
      • library/
        • Zend -> This is where you put Zend Framework
  6. Requirements
    • Zend Framework 1.5 ( http://framework.zend.com )
    • an editor (vi) or IDE (Zend Studio Neon)
    • a (huge) cup of coffee
    • knowledge of XML or INI structures
    • a site already using Zend Framework MVC
  7. Example description
    • We're going to build the following forms:
      • User registration form
      • User login form
      • Password retrieval form
  8. userform.xml – global structure
    • <? xml version = &quot;1.0&quot; encoding = &quot;UTF-8&quot; ?>
    • < forms >
      • < localhost >
        • < user >
          • <!-- our registration form -->
          • <register>
          • </register>
          • <!-- our login form -->
          • < login >
          • </login>
          • <!-- for to request a password reset -->
          • <resetpassword>
          • </resetpassword>
        • </user>
      • </localhost>
    • </forms>
  9. Registration form
    • Full name: the user's full name
    • E-mail address: the user's e-mail address
    • Desired username: the user's username
    • Password: a password for the account
    • Password check: retype the password
  10. userform.xml – registration form 1
    • < register >
      • < action > /app/web/register </ action >
      • < method > post </ method >
      • < name > registerForm </ name >
      • < elements >
        • < fullname >
          • < type > text </ type >
          • < options >
            • < label > Full name: </ label >
          • </options>
        • </fullname>
    • <email>
          • <type> text </type>
          • <options>
            • <label> E-mail address: </label>
          • </options>
        • </email>
        • <username>
    • <type> text </type>
          • <options>
            • <label> Username: </label>
          • </options>
        • </username>
        • <password>
          • <type> password </type>
          • <options>
            • <label> Password: </label>
          • </options>
        • </password>
        • <passwordcheck>
          • <type> password </type>
          • <options>
            • <label> Retype password: </label>
          • </options>
        • </passwordcheck>
        • ...
  11. userform.xml – registration form 2
    • ...
    • <submit>
          • <type> submit </type>
          • <options>
            • <label> Register </label>
            • <class> button </class>
          • </options>
    • </submit>
      • </elements>
    • </register>
  12. Login form
    • Username: the user's username
    • Password: a password for the account
  13. userform.xml – login form 1
    • < login >
      • < action > /app/web/auth </ action >
      • < method > post </ method >
      • < name > login Form </ name >
      • < elements >
        • <username>
    • <type> text </type>
          • <options>
            • <label> Username: </label>
          • </options>
        • </username>
        • <password>
          • <type> password </type>
          • <options>
            • <label> Password: </label>
          • </options>
        • </password>
        • < submit >
          • <type> submit </type>
          • <options>
            • <label> Login </label>
            • <class> button </class>
          • </options>
        • </ submit >
      • </ elements >
    • </login>
  14. Resetpassword form
    • E-mail address: the user's e-mail address
  15. userform.xml – reset pwd form 1
    • < resetpassword >
      • < action > /app/web/resetpassword </ action >
      • < method > post </ method >
      • < name > resetpwd Form </ name >
      • < elements >
        • <email>
    • <type> text </type>
          • <options>
            • <label> E-mail address: </label>
          • </options>
        • </email>
        • <submit>
          • <type> submit </type>
          • <options>
            • <label> Reset password </label>
            • <class> button </class>
          • </options>
        • </submit>
      • </elements>
    • </resetpassword>
  16. UserController - getForm
    • We create a method getForm
    • public function getForm( $myForm )
    • {
      • $config = new Zend_Config_Xml( '../app/config/forms.xml' , 'localhost' );
      • $form = new Zend_Form( $config ->user-> $myForm );
      • return $form ;
    • }
  17. UserController - registerAction
    • We create a method registerAction
    • public function registerAction()
    • {
      • $this ->view->form = $this ->getForm( 'register' );
    • }
    • And we put in the view script (register.phtml):
    • <?php echo $this ->form; ?>
  18. UserController - loginAction
    • We create a method loginAction
    • public function loginAction()
    • {
      • $this ->view->form = $this ->getForm( 'login' );
    • }
    • And we put in the view script (login.phtml):
    • <?php echo $this ->form; ?>
  19. UserController - resetpassworAction
    • We create a method resetpasswordAction
    • public function resetpasswordAction()
    • {
      • $this ->view->form = $this ->getForm( 'resetpassword' );
    • }
    • And we put in the view script (resetpassword.phtml):
    • <?php echo $this ->form; ?>
  20. Rendered register page
  21. Rendered login page
  22. Rendered reset password page
  23. Source code of login page
    • < form name = &quot;loginForm&quot; id = &quot;loginForm&quot; enctype = &quot;application/x-www-form-urlencoded&quot; action = &quot;/app/web/auth&quot; method = &quot;post&quot; >
    • < dl class = &quot;zend_form&quot; >
    • < dt >< label for = &quot;username&quot; class = &quot;optional&quot; >Username:</ label ></ dt >
    • < dd >< input type = &quot;text&quot; name = &quot;username&quot; id = &quot;username&quot; value = &quot;&quot; ></ dd >
    • < dt >< label for = &quot;password&quot; class = &quot;optional&quot; >Password:</ label ></ dt >
    • < dd >< input type = &quot;password&quot; name = &quot;password&quot; id = &quot;password&quot; value = &quot;&quot; ></ dd >
    • < dt ></ dt >
    • < dd >< input type = &quot;submit&quot; name = &quot;submit&quot; id = &quot;submit&quot; value = &quot;Login&quot; class = &quot;button&quot; ></ dd >
    • </ dl >
    • </ form >
    • automated generation using
    • Zend_Form
    • Zend_Config_Xml
  24. Validation and Filtering
    • Of course we need to validate input !
    • And we filter the input !
    • This is done easily in our configuration file
  25. userform.xml – login enhancement
  26. New source code of login page
    • < form name = &quot;loginForm&quot; id = &quot;loginForm&quot; enctype = &quot;application/x-www-form-urlencoded&quot; action = &quot;/app/web/auth&quot; method = &quot;post&quot; >
    • < dl class = &quot;zend_form&quot; >
    • < dt >< label for = &quot;username&quot; class = &quot;required&quot; >Username:</ label ></ dt >
    • < dd >< input type = &quot;text&quot; name = &quot;username&quot; id = &quot;username&quot; value = &quot;&quot; ></ dd >
    • < dt >< label for = &quot;password&quot; class = &quot;required&quot; >Password:</ label ></ dt >
    • < dd >< input type = &quot;password&quot; name = &quot;password&quot; id = &quot;password&quot; value = &quot;&quot; ></ dd >
    • < dt ></ dt >
    • < dd >< input type = &quot;submit&quot; name = &quot;submit&quot; id = &quot;submit&quot; value = &quot;Login&quot; class = &quot;button&quot; ></ dd >
    • </ dl >
    • </ form >
    • automated generation using
    • Zend_Form
    • Zend_Config_Xml
  27. Validation and Filtering details
    • All the validation and filtering options can be found at http://framework.zend.com
    • Zend_Validate
    • Zend_Filter
    • Of course you can implement your own filters and validators.
  28. More information
    • More information can be found at the Zend Framework website http://framework.zend.com
    • The example files can be downloaded at http://www.in2it.be/files/zend_form_example.zip
  29. Thank you Questions ?

+ Michelangelo van DamMichelangelo van Dam, 2 years ago

custom

22503 views, 6 favs, 10 embeds more stats

A mini tutorial about using Zend_Form and Zend_Conf more

More info about this document

CC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs License

Go to text version

  • Total Views 22503
    • 22134 on SlideShare
    • 369 from embeds
  • Comments 7
  • Favorites 6
  • Downloads 429
Most viewed embeds
  • 188 views on http://www.dragonbe.com
  • 93 views on http://dragonbe.blogspot.com
  • 68 views on http://mauriziostorani.wordpress.com
  • 11 views on http://www.planet-php.net
  • 2 views on http://feeds.feedburner.com

more

All embeds
  • 188 views on http://www.dragonbe.com
  • 93 views on http://dragonbe.blogspot.com
  • 68 views on http://mauriziostorani.wordpress.com
  • 11 views on http://www.planet-php.net
  • 2 views on http://feeds.feedburner.com
  • 2 views on https://s3.amazonaws.com
  • 2 views on http://static.slidesharecdn.com
  • 1 views on http://static.slideshare.net
  • 1 views on http://sireesh.blog.co.in
  • 1 views on http://74.125.93.132

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories