SlideShare una empresa de Scribd logo
1 de 26
Descargar para leer sin conexión
Form API
                               Til All Are One



Thursday, September 20, 2007                     1
The Olden Days

                    • HTML
                    • Helper Functions
                    • Duplicate Work
                    • Weak Security

Thursday, September 20, 2007                    2
Baby Jesus




                                   Node Forms


Thursday, September 20, 2007                    3
Form API Basics

                    • Structured Data
                    • Workflow
                    • Best Practices
                    • Render to HTML

Thursday, September 20, 2007                     4
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
Form API Basics




Thursday, September 20, 2007                     6
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
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
New In Drupal 6


Thursday, September 20, 2007       9
IM IN UR FORMZ
           RENAMIN UR BUTTONZ
Thursday, September 20, 2007    10
•          Button Handlers

                    • $op is dead

                    • Image buttons!

                    • Buttons renamable

                    • AHAH

Thursday, September 20, 2007                     11
WANT MAH
                               FORM STATE
Thursday, September 20, 2007                12
•          Form State

                    • Input Values

                    • Workflow

                    • Storage

                    • No Globals

Thursday, September 20, 2007                13
#MULTISTEP!?!11!
               DO NOT WANT
Thursday, September 20, 2007      14
•          All Forms

                    • Just Set ‘rebuild’

                    • Forms Cached

                    • Handlers In Control

                    • Validation, too!

Thursday, September 20, 2007                15
FORMZ CAT IZ BORED.
                         WE HAZ EXAMPLE

Thursday, September 20, 2007                 16
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
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
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
Thursday, September 20, 2007   20
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
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
Here’s Where It
                               Starts To Rock
Thursday, September 20, 2007                     23
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
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
And Then the
                               Ewoks Danced


Thursday, September 20, 2007                  26

Más contenido relacionado

La actualidad más candente

Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016Colin O'Dell
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Knowgirish82
 
Instant Dynamic Forms with #states
Instant Dynamic Forms with #statesInstant Dynamic Forms with #states
Instant Dynamic Forms with #statesKonstantin Käfer
 
Let jQuery Rock Your World
Let jQuery Rock Your WorldLet jQuery Rock Your World
Let jQuery Rock Your WorldMatt Gifford
 
ZG PHP - Specification
ZG PHP - SpecificationZG PHP - Specification
ZG PHP - SpecificationRobert Šorn
 
Who Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniterWho Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniterciconf
 
Taming forms with React
Taming forms with ReactTaming forms with React
Taming forms with ReactGreeceJS
 
Beyond the Final Frontier of jQuery Selectors
Beyond the Final Frontier of jQuery SelectorsBeyond the Final Frontier of jQuery Selectors
Beyond the Final Frontier of jQuery SelectorsAlexander Shopov
 
Perl调用微博API实现自动查询应答
Perl调用微博API实现自动查询应答Perl调用微博API实现自动查询应答
Perl调用微博API实现自动查询应答琛琳 饶
 
JavaOne 2017 | JShell: The Ultimate Missing Tool
 JavaOne 2017 | JShell: The Ultimate Missing Tool JavaOne 2017 | JShell: The Ultimate Missing Tool
JavaOne 2017 | JShell: The Ultimate Missing ToolHakan Özler
 
WordPress overloading Gravityforms using hooks, filters and extending classes
WordPress overloading Gravityforms using hooks, filters and extending classes WordPress overloading Gravityforms using hooks, filters and extending classes
WordPress overloading Gravityforms using hooks, filters and extending classes Paul Bearne
 
Gravity Forms Hooks & Filters
Gravity Forms Hooks & FiltersGravity Forms Hooks & Filters
Gravity Forms Hooks & Filtersiamdangavin
 
Javascript session june 2013 (iii) jquery json
Javascript session june 2013 (iii) jquery   jsonJavascript session june 2013 (iii) jquery   json
Javascript session june 2013 (iii) jquery jsonabksharma
 
Drupal sins 2016 10-06
Drupal sins 2016 10-06Drupal sins 2016 10-06
Drupal sins 2016 10-06Aaron Crosman
 

La actualidad más candente (19)

Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Know
 
Instant Dynamic Forms with #states
Instant Dynamic Forms with #statesInstant Dynamic Forms with #states
Instant Dynamic Forms with #states
 
Let jQuery Rock Your World
Let jQuery Rock Your WorldLet jQuery Rock Your World
Let jQuery Rock Your World
 
ZG PHP - Specification
ZG PHP - SpecificationZG PHP - Specification
ZG PHP - Specification
 
Who Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniterWho Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniter
 
Taming forms with React
Taming forms with ReactTaming forms with React
Taming forms with React
 
Beyond the Final Frontier of jQuery Selectors
Beyond the Final Frontier of jQuery SelectorsBeyond the Final Frontier of jQuery Selectors
Beyond the Final Frontier of jQuery Selectors
 
PhoneGap: Local Storage
PhoneGap: Local StoragePhoneGap: Local Storage
PhoneGap: Local Storage
 
Perl调用微博API实现自动查询应答
Perl调用微博API实现自动查询应答Perl调用微博API实现自动查询应答
Perl调用微博API实现自动查询应答
 
Keeping It Simple
Keeping It SimpleKeeping It Simple
Keeping It Simple
 
JavaOne 2017 | JShell: The Ultimate Missing Tool
 JavaOne 2017 | JShell: The Ultimate Missing Tool JavaOne 2017 | JShell: The Ultimate Missing Tool
JavaOne 2017 | JShell: The Ultimate Missing Tool
 
WordPress overloading Gravityforms using hooks, filters and extending classes
WordPress overloading Gravityforms using hooks, filters and extending classes WordPress overloading Gravityforms using hooks, filters and extending classes
WordPress overloading Gravityforms using hooks, filters and extending classes
 
Gravity Forms Hooks & Filters
Gravity Forms Hooks & FiltersGravity Forms Hooks & Filters
Gravity Forms Hooks & Filters
 
Javascript session june 2013 (iii) jquery json
Javascript session june 2013 (iii) jquery   jsonJavascript session june 2013 (iii) jquery   json
Javascript session june 2013 (iii) jquery json
 
Introducing jQuery
Introducing jQueryIntroducing jQuery
Introducing jQuery
 
Postgresql and ror
Postgresql and rorPostgresql and ror
Postgresql and ror
 
Php if
Php ifPhp if
Php if
 
Drupal sins 2016 10-06
Drupal sins 2016 10-06Drupal sins 2016 10-06
Drupal sins 2016 10-06
 

Más de Jeff Eaton

This Is not a Place of Honor
This Is not a Place of HonorThis Is not a Place of Honor
This Is not a Place of HonorJeff Eaton
 
An API Won't Fix Your Content Problem
An API Won't Fix Your Content ProblemAn API Won't Fix Your Content Problem
An API Won't Fix Your Content ProblemJeff Eaton
 
Hello, {{FIRSTNAME}}, My Old Friend
Hello, {{FIRSTNAME}}, My Old FriendHello, {{FIRSTNAME}}, My Old Friend
Hello, {{FIRSTNAME}}, My Old FriendJeff Eaton
 
Maps, Models, and Teams
Maps, Models, and TeamsMaps, Models, and Teams
Maps, Models, and TeamsJeff Eaton
 
Collaborative Content Modeling
Collaborative Content ModelingCollaborative Content Modeling
Collaborative Content ModelingJeff Eaton
 
Adventures in Drupal 8
Adventures in Drupal 8Adventures in Drupal 8
Adventures in Drupal 8Jeff Eaton
 
Modeling Rich Narrative Content
Modeling Rich Narrative ContentModeling Rich Narrative Content
Modeling Rich Narrative ContentJeff Eaton
 
Battle for the Body Field (DrupalCon)
Battle for the Body Field (DrupalCon)Battle for the Body Field (DrupalCon)
Battle for the Body Field (DrupalCon)Jeff Eaton
 
The Battle For The Body Field
The Battle For The Body FieldThe Battle For The Body Field
The Battle For The Body FieldJeff Eaton
 
Workflow That Works Under Pressure
Workflow That Works Under PressureWorkflow That Works Under Pressure
Workflow That Works Under PressureJeff Eaton
 
Planning Beyond the Page
Planning Beyond the PagePlanning Beyond the Page
Planning Beyond the PageJeff Eaton
 
Building Your Agency's Content Strategy Practice
Building Your Agency's Content Strategy PracticeBuilding Your Agency's Content Strategy Practice
Building Your Agency's Content Strategy PracticeJeff Eaton
 
Deblobbing In The Real World
Deblobbing In The Real WorldDeblobbing In The Real World
Deblobbing In The Real WorldJeff Eaton
 
Prepare for the Mobilacalypse
Prepare for the MobilacalypsePrepare for the Mobilacalypse
Prepare for the MobilacalypseJeff Eaton
 
Drupal in Action (CMS Expo 2011)
Drupal in Action (CMS Expo 2011)Drupal in Action (CMS Expo 2011)
Drupal in Action (CMS Expo 2011)Jeff Eaton
 
Baby Got Backend (CMS Expo 2011)
Baby Got Backend (CMS Expo 2011)Baby Got Backend (CMS Expo 2011)
Baby Got Backend (CMS Expo 2011)Jeff Eaton
 
The Platypus Problem
The Platypus ProblemThe Platypus Problem
The Platypus ProblemJeff Eaton
 
Drupal in Action
Drupal in ActionDrupal in Action
Drupal in ActionJeff Eaton
 
Architecture Is For Everyone
Architecture Is For EveryoneArchitecture Is For Everyone
Architecture Is For EveryoneJeff Eaton
 

Más de Jeff Eaton (20)

This Is not a Place of Honor
This Is not a Place of HonorThis Is not a Place of Honor
This Is not a Place of Honor
 
An API Won't Fix Your Content Problem
An API Won't Fix Your Content ProblemAn API Won't Fix Your Content Problem
An API Won't Fix Your Content Problem
 
Hello, {{FIRSTNAME}}, My Old Friend
Hello, {{FIRSTNAME}}, My Old FriendHello, {{FIRSTNAME}}, My Old Friend
Hello, {{FIRSTNAME}}, My Old Friend
 
Maps, Models, and Teams
Maps, Models, and TeamsMaps, Models, and Teams
Maps, Models, and Teams
 
Collaborative Content Modeling
Collaborative Content ModelingCollaborative Content Modeling
Collaborative Content Modeling
 
Adventures in Drupal 8
Adventures in Drupal 8Adventures in Drupal 8
Adventures in Drupal 8
 
Recoupling
RecouplingRecoupling
Recoupling
 
Modeling Rich Narrative Content
Modeling Rich Narrative ContentModeling Rich Narrative Content
Modeling Rich Narrative Content
 
Battle for the Body Field (DrupalCon)
Battle for the Body Field (DrupalCon)Battle for the Body Field (DrupalCon)
Battle for the Body Field (DrupalCon)
 
The Battle For The Body Field
The Battle For The Body FieldThe Battle For The Body Field
The Battle For The Body Field
 
Workflow That Works Under Pressure
Workflow That Works Under PressureWorkflow That Works Under Pressure
Workflow That Works Under Pressure
 
Planning Beyond the Page
Planning Beyond the PagePlanning Beyond the Page
Planning Beyond the Page
 
Building Your Agency's Content Strategy Practice
Building Your Agency's Content Strategy PracticeBuilding Your Agency's Content Strategy Practice
Building Your Agency's Content Strategy Practice
 
Deblobbing In The Real World
Deblobbing In The Real WorldDeblobbing In The Real World
Deblobbing In The Real World
 
Prepare for the Mobilacalypse
Prepare for the MobilacalypsePrepare for the Mobilacalypse
Prepare for the Mobilacalypse
 
Drupal in Action (CMS Expo 2011)
Drupal in Action (CMS Expo 2011)Drupal in Action (CMS Expo 2011)
Drupal in Action (CMS Expo 2011)
 
Baby Got Backend (CMS Expo 2011)
Baby Got Backend (CMS Expo 2011)Baby Got Backend (CMS Expo 2011)
Baby Got Backend (CMS Expo 2011)
 
The Platypus Problem
The Platypus ProblemThe Platypus Problem
The Platypus Problem
 
Drupal in Action
Drupal in ActionDrupal in Action
Drupal in Action
 
Architecture Is For Everyone
Architecture Is For EveryoneArchitecture Is For Everyone
Architecture Is For Everyone
 

Último

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 

Último (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 

Form API 3

  • 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
  • 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