Form API 3

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.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    8 Favorites

    Form API 3 - Presentation Transcript

    1. Form API Til All Are One Thursday, September 20, 2007 1
    2. The Olden Days • HTML • Helper Functions • Duplicate Work • Weak Security Thursday, September 20, 2007 2
    3. Baby Jesus Node Forms Thursday, September 20, 2007 3
    4. Form API Basics • Structured Data • Workflow • Best Practices • Render to HTML Thursday, September 20, 2007 4
    5. Form API Basics function my_form() { $form = array(); $form['foo'] = array( '#type' => 'textarea', '#title' => t('Your foo'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit yo foo'), ); return $form; } Thursday, September 20, 2007 5
    6. Form API Basics Thursday, September 20, 2007 6
    7. Behind The Scenes • drupal_get_form(‘my_form’) • my_form() • $_POST, XSS, XSRF • my_form_validate() • my_form_submit() • drupal_render() Thursday, September 20, 2007 7
    8. Stupid Form Tricks • hook_forms() Map form IDs • hook_elements() Add new form elements • hook_form_alter() Change any form Thursday, September 20, 2007 8
    9. New In Drupal 6 Thursday, September 20, 2007 9
    10. IM IN UR FORMZ RENAMIN UR BUTTONZ Thursday, September 20, 2007 10
    11. • Button Handlers • $op is dead • Image buttons! • Buttons renamable • AHAH Thursday, September 20, 2007 11
    12. WANT MAH FORM STATE Thursday, September 20, 2007 12
    13. • Form State • Input Values • Workflow • Storage • No Globals Thursday, September 20, 2007 13
    14. #MULTISTEP!?!11! DO NOT WANT Thursday, September 20, 2007 14
    15. • All Forms • Just Set ‘rebuild’ • Forms Cached • Handlers In Control • Validation, too! Thursday, September 20, 2007 15
    16. FORMZ CAT IZ BORED. WE HAZ EXAMPLE Thursday, September 20, 2007 16
    17. Multiple Buttons function my_form() { ... $form['submit'] = array( '#type' => 'submit', '#title' => t('Your foo'), ); $form['delete'] = array( '#type' => 'submit', '#value' => t('Preview'), '#submit' => array('delete_submit'), '#validate' => array('delete_validate'), ); return $form; } Thursday, September 20, 2007 17
    18. Multiple Buttons function delete_validate(&$form_state) { $values = $form_state['values']; if (empty($values['foo'])) { form_set_error('title', t('No! Bad!'); } } function delete_submit(&$form_state) { $values = $form_state['values']; // Delete Yo Stuff! $form_state['redirect'] = '<front>'; } Thursday, September 20, 2007 18
    19. Multiple Buttons function my_button_handler(&$form_state) { $button = $form_state['clicked_button']; if ($button['#my_special_flag']) { // Do custom stuff here } } Thursday, September 20, 2007 19
    20. Thursday, September 20, 2007 20
    21. Multi-page Form function my_form($form_state) { if (empty($form_state[‘step’]) { $form_state[‘step’] = 1; } switch ($form_state[‘step’]) { case 1: ... case 2: ... case 3: ... } } Thursday, September 20, 2007 21
    22. Multi-page Form function my_form_submit($form_state) { $values = $form_state[‘values’]; $form_state[‘step’] = $values[‘step’]++; if ($form_state[‘step’] < 3) { $form_state[‘rebuild’] = TRUE; } } Thursday, September 20, 2007 22
    23. Here’s Where It Starts To Rock Thursday, September 20, 2007 23
    24. Conditional CAPTCHA function my_form_alter(&$form, $form_id, $form_state) { $form['#validate'][] = 'captcha_validate'; if ($form_state['needs_captcha']) { // Add a captcha form! } } Thursday, September 20, 2007 24
    25. Conditional CAPTCHA function captcha_validate(&$form_state) { $values = $form_state['values']; if (!empty($values['captcha'])) { if (captcha_failed($values['captcha'])) { form_set_error('title', t('No! Bad spammer!')); } } elseif (is_spammy($values)) { $form_state['needs_captcha'] = TRUE; $form_state['rebuild'] = TRUE; } } } Thursday, September 20, 2007 25
    26. And Then the Ewoks Danced Thursday, September 20, 2007 26

    + Jeff EatonJeff Eaton, 3 years ago

    custom

    5496 views, 8 favs, 3 embeds more stats

    An overview of Drupal's form handling API, and a lo more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 5496
      • 5253 on SlideShare
      • 243 from embeds
    • Comments 0
    • Favorites 8
    • Downloads 228
    Most viewed embeds
    • 239 views on http://jeff.viapositiva.net
    • 2 views on http://www.incubationoakland.com
    • 2 views on http://localhost

    more

    All embeds
    • 239 views on http://jeff.viapositiva.net
    • 2 views on http://www.incubationoakland.com
    • 2 views on http://localhost

    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