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

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 

Último (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 

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