SlideShare una empresa de Scribd logo
1 de 15
Descargar para leer sin conexión
Forms API Inside Out
  Or, How I Learned to Stop Worrying
      and Love the Nested Arrays




                                       1
The Olden Days
In the beginning, there was HTML
Then, there were helper functions
Each form had to reinvent workflow
Each form had to reinvent security
The Node Form made Baby Jesus cry

                                     2
Drupal’s Answer: Forms API

Build forms as structured data
Make the workflow automatic
Make ‘doing the right thing’ easy
When everything is done, render to HTML


                                          3
So, What’s It Look Like?
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;
}

                                         4
So, What’s It Look Like?




                           5
How to Use Your Form
drupal_get_form('my_form')

my_form()

my_form_validate(...)

my_form_submit(...)
                             6
Behind the Scenes

    http://foo.com/my-form
                 my_form_page()
      drupal_get_form('my_form')
                       my_form()
           (Here, magic happens*)
             drupal_render($form)
                                    7
Behind the Scenes (Part 2)

   Here’s that form you gave me
       drupal_get_form('my_form')
                   $_POST has data!
                         my_form()
              my_form_validate(...)
                my_form_submit(...)
                                      8
Recap, With Kittens
Call drupal_get_form(‘my_form’)
The my_form() function builds an array
   Drupal sanity checks $_POST
   The my_form_validate() function validates
   The my_form_submit() function processes
The drupal_render() function outputs the form.
                                                 T. Keller
                                                             9
Here’s the Magic
Build the initial form definition
drupal_process_form()
   drupal_build_form()
       hook_form_alter()
       _form_builder()

                                   10
Here’s the Magic
_form_builder() does a lot!
Handles defaults
Weaves $_POST into the form
Builds $form_values
Inserts security tokens

                              11
“Special” Bits

hook_elements()
hook_form_alter()
drupal_execute()



                    12
Current Limitations

Dynamic AHAH/AJAX
Wizard-style forms
Too many special cases
AHAH/AJAX security!


                         13
The Future of Forms API

Form chunks
State management
AHAH/AJAX security



                          14
Whee!




        15

Más contenido relacionado

La actualidad más candente

PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
Five things for you - Yahoo developer offers
Five things for you - Yahoo developer offersFive things for you - Yahoo developer offers
Five things for you - Yahoo developer offersChristian Heilmann
 
Drupal 8: Routing & More
Drupal 8: Routing & MoreDrupal 8: Routing & More
Drupal 8: Routing & Moredrubb
 
Mikhail Kraynuk. Form api. Drupal 8
Mikhail Kraynuk. Form api. Drupal 8Mikhail Kraynuk. Form api. Drupal 8
Mikhail Kraynuk. Form api. Drupal 8i20 Group
 
Drupal 8: Forms
Drupal 8: FormsDrupal 8: Forms
Drupal 8: Formsdrubb
 
The Truth About Lambdas in PHP
The Truth About Lambdas in PHPThe Truth About Lambdas in PHP
The Truth About Lambdas in PHPSharon Levy
 
Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, Germany
Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, GermanyLet's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, Germany
Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, GermanyBalázs Tatár
 
Phpで作るmovable typeプラグイン
Phpで作るmovable typeプラグインPhpで作るmovable typeプラグイン
Phpで作るmovable typeプラグインYuji Takayama
 
Let's write secure Drupal code!
Let's write secure Drupal code!Let's write secure Drupal code!
Let's write secure Drupal code!Balázs Tatár
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the newRemy Sharp
 
Advanced jQuery
Advanced jQueryAdvanced jQuery
Advanced jQuerysergioafp
 

La actualidad más candente (20)

Bacbkone js
Bacbkone jsBacbkone js
Bacbkone js
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Keeping It Simple
Keeping It SimpleKeeping It Simple
Keeping It Simple
 
Five things for you - Yahoo developer offers
Five things for you - Yahoo developer offersFive things for you - Yahoo developer offers
Five things for you - Yahoo developer offers
 
10. view one record
10. view one record10. view one record
10. view one record
 
11. delete record
11. delete record11. delete record
11. delete record
 
12. edit record
12. edit record12. edit record
12. edit record
 
Drupal 8: Routing & More
Drupal 8: Routing & MoreDrupal 8: Routing & More
Drupal 8: Routing & More
 
Mikhail Kraynuk. Form api. Drupal 8
Mikhail Kraynuk. Form api. Drupal 8Mikhail Kraynuk. Form api. Drupal 8
Mikhail Kraynuk. Form api. Drupal 8
 
Drupal 8: Forms
Drupal 8: FormsDrupal 8: Forms
Drupal 8: Forms
 
The Truth About Lambdas in PHP
The Truth About Lambdas in PHPThe Truth About Lambdas in PHP
The Truth About Lambdas in PHP
 
20. CodeIgniter edit images
20. CodeIgniter edit images20. CodeIgniter edit images
20. CodeIgniter edit images
 
Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, Germany
Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, GermanyLet's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, Germany
Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, Germany
 
Phpで作るmovable typeプラグイン
Phpで作るmovable typeプラグインPhpで作るmovable typeプラグイン
Phpで作るmovable typeプラグイン
 
Let's write secure Drupal code!
Let's write secure Drupal code!Let's write secure Drupal code!
Let's write secure Drupal code!
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
 
Taming Command Bus
Taming Command BusTaming Command Bus
Taming Command Bus
 
Backbone - TDC 2011 Floripa
Backbone - TDC 2011 FloripaBackbone - TDC 2011 Floripa
Backbone - TDC 2011 Floripa
 
Advanced jQuery
Advanced jQueryAdvanced jQuery
Advanced jQuery
 
8. vederea inregistrarilor
8. vederea inregistrarilor8. vederea inregistrarilor
8. vederea inregistrarilor
 

Similar a Form API Intro

Drupal is Stupid (But I Love It Anyway)
Drupal is Stupid (But I Love It Anyway)Drupal is Stupid (But I Love It Anyway)
Drupal is Stupid (But I Love It Anyway)brockboland
 
What's new in the Drupal 7 API?
What's new in the Drupal 7 API?What's new in the Drupal 7 API?
What's new in the Drupal 7 API?Alexandru Badiu
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)Jeff Eaton
 
Debugging in drupal 8
Debugging in drupal 8Debugging in drupal 8
Debugging in drupal 8Allie Jones
 
You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix itRafael Dohms
 
Apostrophe
ApostropheApostrophe
Apostrophetompunk
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ EtsyNishan Subedi
 
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2eugenio pombi
 
Mikhail Kraynuk. Form api. Drupal 8
Mikhail Kraynuk. Form api. Drupal 8Mikhail Kraynuk. Form api. Drupal 8
Mikhail Kraynuk. Form api. Drupal 8DrupalSib
 
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 JavascriptjQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 JavascriptDarren Mothersele
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
Task 2
Task 2Task 2
Task 2EdiPHP
 
Symfony CoP: Form component
Symfony CoP: Form componentSymfony CoP: Form component
Symfony CoP: Form componentSamuel ROZE
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your CodeAbbas Ali
 
Learning the basics of the Drupal API
Learning the basics of the Drupal APILearning the basics of the Drupal API
Learning the basics of the Drupal APIAlexandru Badiu
 

Similar a Form API Intro (20)

Drupal is Stupid (But I Love It Anyway)
Drupal is Stupid (But I Love It Anyway)Drupal is Stupid (But I Love It Anyway)
Drupal is Stupid (But I Love It Anyway)
 
What's new in the Drupal 7 API?
What's new in the Drupal 7 API?What's new in the Drupal 7 API?
What's new in the Drupal 7 API?
 
D8 Form api
D8 Form apiD8 Form api
D8 Form api
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
 
Debugging in drupal 8
Debugging in drupal 8Debugging in drupal 8
Debugging in drupal 8
 
You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix it
 
Apostrophe
ApostropheApostrophe
Apostrophe
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Fatc
FatcFatc
Fatc
 
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
 
Mikhail Kraynuk. Form api. Drupal 8
Mikhail Kraynuk. Form api. Drupal 8Mikhail Kraynuk. Form api. Drupal 8
Mikhail Kraynuk. Form api. Drupal 8
 
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 JavascriptjQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Task 2
Task 2Task 2
Task 2
 
Symfony CoP: Form component
Symfony CoP: Form componentSymfony CoP: Form component
Symfony CoP: Form component
 
Fapi
FapiFapi
Fapi
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your Code
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
Get on with Field API
Get on with Field APIGet on with Field API
Get on with Field API
 
Learning the basics of the Drupal API
Learning the basics of the Drupal APILearning the basics of the Drupal API
Learning the basics of the Drupal API
 

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

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Último (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

Form API Intro

  • 1. Forms API Inside Out Or, How I Learned to Stop Worrying and Love the Nested Arrays 1
  • 2. The Olden Days In the beginning, there was HTML Then, there were helper functions Each form had to reinvent workflow Each form had to reinvent security The Node Form made Baby Jesus cry 2
  • 3. Drupal’s Answer: Forms API Build forms as structured data Make the workflow automatic Make ‘doing the right thing’ easy When everything is done, render to HTML 3
  • 4. So, What’s It Look Like? 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; } 4
  • 5. So, What’s It Look Like? 5
  • 6. How to Use Your Form drupal_get_form('my_form') my_form() my_form_validate(...) my_form_submit(...) 6
  • 7. Behind the Scenes http://foo.com/my-form my_form_page() drupal_get_form('my_form') my_form() (Here, magic happens*) drupal_render($form) 7
  • 8. Behind the Scenes (Part 2) Here’s that form you gave me drupal_get_form('my_form') $_POST has data! my_form() my_form_validate(...) my_form_submit(...) 8
  • 9. Recap, With Kittens Call drupal_get_form(‘my_form’) The my_form() function builds an array Drupal sanity checks $_POST The my_form_validate() function validates The my_form_submit() function processes The drupal_render() function outputs the form. T. Keller 9
  • 10. Here’s the Magic Build the initial form definition drupal_process_form() drupal_build_form() hook_form_alter() _form_builder() 10
  • 11. Here’s the Magic _form_builder() does a lot! Handles defaults Weaves $_POST into the form Builds $form_values Inserts security tokens 11
  • 13. Current Limitations Dynamic AHAH/AJAX Wizard-style forms Too many special cases AHAH/AJAX security! 13
  • 14. The Future of Forms API Form chunks State management AHAH/AJAX security 14
  • 15. Whee! 15