SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
Form API 101
Intro to building Forms in Drupal using PHP	

!
!
presented by Chris Charlton	

http://xtnd.us
Drupal uses PHP Arrays for forms
• Easy to Add, Remove, or Alter:	

• Form fields & their attributes	

• Validation & Submit handling	

• Form tag & attributes	

• Write less code	

• Reduces markup errors
Form Field Types
• Text input	

• File input/upload	

• Select Lists/Menu/Dropdowns	

• Checkboxes, Radiobuttons	

• Lots of types, or make your own!
Before we talk Drupal...
• <form> HTML tag 	

• PHP code summary	

• Basics	

• Arrays
<form>
<form id="unique-form-id" action="form_action.php">

First name: <input type="text" name="firstname" />

Last name: <input type="text" name="lastname" />

<input type="submit" value="Submit" />

</form>	
!
!
!
PHP required... but how much?
• Basic PHP	

• Strings & Numbers	

• Variables	

• Functions	

!
!
• Arrays	

• Keys	

• Values	

• Multidimensional/Tree
PHP Basics
Strings - “this is a string”	
Numbers - 1234567890	

Variables - $long_var_name = 123;	
Functions - hook_form()
PHP Arrays
<?php

// Declare new basic array of numbers up to ten

$array_of_numbers = array(0, 1, 2, 3, 4, 5, 6, 7, 8);

$array_of_numbers[] = 9; // Add an array item

$array_of_numbers[] = 10; // Add another item



//Declare new basic array of strings

$array_of_strings = array(‘A’, ‘b’, ‘C’, ‘d’, ‘E’);	
!
Mixed Key PHP Array
<?php

// Declare multidimensional array with mixed keys

$mixed_array = array(

0 => ‘index zero has this string value’,

1 => ‘index one has this similar string value’,

‘two’ => ‘index two has a string key’,

‘three’ => ‘index three also has a string key’,

4 => ‘index four is a numeric key like index 0 & 1’

);	
!
Multidimensional PHP Array
<?php

// Declare multidimensional array with mixed keys

$multidim_array = array(

0 => array(

“person0” => “Jay”,

“person1” => “Silent Bob”,

“person2” => “Chris”

),

1 => ‘index one has this similar string value’,

‘two’ => ‘index two has a string key’,

‘three’ => ‘index three also has a string key’,

4 => ‘index four is a numeric key like index 0 & 1’

);
Form API
a.k.a “FAPI”
Form API - Textfield
<?php



$form[‘firstname’] = array(

‘#type‘ => ‘textfield’,

‘#title‘ => t(‘First name’),

);



Form parts you build
<form id="simple-form" action="">

First name: <input type="text" name="firstname" />

Last name: <input type="text" name="lastname" />

<input type="submit" value="Submit" />

</form>	
!
!
!
Same form in PHP using
Drupal’s Form API<?php	
// Simple function returns simple form array

function simple_form() {

$form = array();

$form[‘firstname’] = array(

‘#type‘ => ‘textfield’,

‘#title‘ => t(‘First name’),

);

$form[‘lastname’] = array(

‘#type‘ => ‘textfield’,

‘#title‘ => t(‘Last name’),

);

$form[‘submit’] = array(

‘#type‘ => ‘submit’,

‘#title‘ => t(‘Submit’),

);

return $form;

}
<?php	
// Call in that custom form

function custom_form_page() {

return drupal_get_form(‘simple_form’);

}
Homework #1:
Try out all form types
Homework #2:
Read and learn these...
hook_forms()
• Hook that lets you declare all known forms
within your module and assigns Form ID’s	

• “hook_” replaced “your_module_name_”
hook_form_alter()
• The hook allowing you to alter all forms	

• “hook_” replaced “your_module_name_” 	

• Specific form: hook_form_FORM_ID_alter()
Learn more
• http://api.drupal.org	

• http://drupal.org/project/examples	

• http://drupal.org	

• http://drupalcampla.com

Contenu connexe

Tendances

Advanced Internationalization with Rails
Advanced Internationalization with RailsAdvanced Internationalization with Rails
Advanced Internationalization with Rails
Clinton Dreisbach
 
Zend_Form to the Rescue - A Brief Introduction to Zend_Form
Zend_Form to the Rescue - A Brief Introduction to Zend_FormZend_Form to the Rescue - A Brief Introduction to Zend_Form
Zend_Form to the Rescue - A Brief Introduction to Zend_Form
Jeremy Kendall
 

Tendances (20)

PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Building Data Mapper PHP5
Building Data Mapper PHP5Building Data Mapper PHP5
Building Data Mapper PHP5
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
Advanced Internationalization with Rails
Advanced Internationalization with RailsAdvanced Internationalization with Rails
Advanced Internationalization with Rails
 
PHP - Introduction to PHP Functions
PHP -  Introduction to PHP FunctionsPHP -  Introduction to PHP Functions
PHP - Introduction to PHP Functions
 
PHP Built-in String Validation Functions
PHP Built-in String Validation FunctionsPHP Built-in String Validation Functions
PHP Built-in String Validation Functions
 
PHPLinq
PHPLinqPHPLinq
PHPLinq
 
6 global library function provided by open cart
6 global library function provided by open cart6 global library function provided by open cart
6 global library function provided by open cart
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 
Php variables (english)
Php variables (english)Php variables (english)
Php variables (english)
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-Kjaer
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
 
Defensive Coding Crash Course Tutorial
Defensive Coding Crash Course TutorialDefensive Coding Crash Course Tutorial
Defensive Coding Crash Course Tutorial
 
CSS3 and Selectors
CSS3 and SelectorsCSS3 and Selectors
CSS3 and Selectors
 
Zend_Form to the Rescue - A Brief Introduction to Zend_Form
Zend_Form to the Rescue - A Brief Introduction to Zend_FormZend_Form to the Rescue - A Brief Introduction to Zend_Form
Zend_Form to the Rescue - A Brief Introduction to Zend_Form
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
 
Scala syntax analysis
Scala syntax analysisScala syntax analysis
Scala syntax analysis
 

Similaire à Drupal Form API 101 (PHP) - DrupalCamp LA 2012

Similaire à Drupal Form API 101 (PHP) - DrupalCamp LA 2012 (20)

PHP-04-Forms.ppt
PHP-04-Forms.pptPHP-04-Forms.ppt
PHP-04-Forms.ppt
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
 
PHP - Introduction to PHP Forms
PHP - Introduction to PHP FormsPHP - Introduction to PHP Forms
PHP - Introduction to PHP Forms
 
03-forms.ppt.pptx
03-forms.ppt.pptx03-forms.ppt.pptx
03-forms.ppt.pptx
 
Php Basics
Php BasicsPhp Basics
Php Basics
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array.
 
PHP
PHPPHP
PHP
 
php (Hypertext Preprocessor)
php (Hypertext Preprocessor)php (Hypertext Preprocessor)
php (Hypertext Preprocessor)
 
Php Intermediate
Php IntermediatePhp Intermediate
Php Intermediate
 
Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
 
Working with data.pptx
Working with data.pptxWorking with data.pptx
Working with data.pptx
 
Advancing Your Custom Fields - WordCamp 2014
Advancing Your Custom Fields - WordCamp 2014Advancing Your Custom Fields - WordCamp 2014
Advancing Your Custom Fields - WordCamp 2014
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
PHP Experience 2016 - [Workshop] Elastic Search: Turbinando sua aplicação PHP
PHP Experience 2016 - [Workshop] Elastic Search: Turbinando sua aplicação PHPPHP Experience 2016 - [Workshop] Elastic Search: Turbinando sua aplicação PHP
PHP Experience 2016 - [Workshop] Elastic Search: Turbinando sua aplicação PHP
 

Plus de Chris Charlton

Lightning Talk: Drush aliases (Drupal Camp LA 2013)
Lightning Talk: Drush aliases (Drupal Camp LA 2013)Lightning Talk: Drush aliases (Drupal Camp LA 2013)
Lightning Talk: Drush aliases (Drupal Camp LA 2013)
Chris Charlton
 
Site Aliases: Powerful Drupal Administration Using Drush by Chris Charlton
Site Aliases: Powerful Drupal Administration Using Drush by Chris CharltonSite Aliases: Powerful Drupal Administration Using Drush by Chris Charlton
Site Aliases: Powerful Drupal Administration Using Drush by Chris Charlton
Chris Charlton
 
Policy File: Powerful Drupal Administration Using Drush
Policy File: Powerful Drupal Administration Using DrushPolicy File: Powerful Drupal Administration Using Drush
Policy File: Powerful Drupal Administration Using Drush
Chris Charlton
 

Plus de Chris Charlton (11)

Drupal Developer Skills (2012) - DrupalCamp LA 2012
Drupal Developer Skills (2012) - DrupalCamp LA 2012Drupal Developer Skills (2012) - DrupalCamp LA 2012
Drupal Developer Skills (2012) - DrupalCamp LA 2012
 
Sassy CSS (part 2) (Drupal Camp LA 2013)
Sassy CSS (part 2) (Drupal Camp LA 2013)Sassy CSS (part 2) (Drupal Camp LA 2013)
Sassy CSS (part 2) (Drupal Camp LA 2013)
 
Lightning Talk: Drush aliases (Drupal Camp LA 2013)
Lightning Talk: Drush aliases (Drupal Camp LA 2013)Lightning Talk: Drush aliases (Drupal Camp LA 2013)
Lightning Talk: Drush aliases (Drupal Camp LA 2013)
 
Site Aliases: Powerful Drupal Administration Using Drush by Chris Charlton
Site Aliases: Powerful Drupal Administration Using Drush by Chris CharltonSite Aliases: Powerful Drupal Administration Using Drush by Chris Charlton
Site Aliases: Powerful Drupal Administration Using Drush by Chris Charlton
 
Policy File: Powerful Drupal Administration Using Drush
Policy File: Powerful Drupal Administration Using DrushPolicy File: Powerful Drupal Administration Using Drush
Policy File: Powerful Drupal Administration Using Drush
 
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris CharltonDrush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
 
Changes to Drupal Themes in version 7 (part 1)
Changes to Drupal Themes in version 7 (part 1)Changes to Drupal Themes in version 7 (part 1)
Changes to Drupal Themes in version 7 (part 1)
 
Web Content Management Systems From A Designer's Perspective (Drupal Technica...
Web Content Management Systems From A Designer's Perspective (Drupal Technica...Web Content Management Systems From A Designer's Perspective (Drupal Technica...
Web Content Management Systems From A Designer's Perspective (Drupal Technica...
 
Let's Zen! (Stop Theming From Scratch)
Let's Zen! (Stop Theming From Scratch)Let's Zen! (Stop Theming From Scratch)
Let's Zen! (Stop Theming From Scratch)
 
Flex Flash Air Interfaces for Custom Content Types in Drupal Chris Charlton
Flex Flash Air Interfaces for Custom Content Types in Drupal   Chris CharltonFlex Flash Air Interfaces for Custom Content Types in Drupal   Chris Charlton
Flex Flash Air Interfaces for Custom Content Types in Drupal Chris Charlton
 
Better Drupal Interaction Design with Flex
Better Drupal Interaction Design with FlexBetter Drupal Interaction Design with Flex
Better Drupal Interaction Design with Flex
 

Dernier

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Dernier (20)

%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 

Drupal Form API 101 (PHP) - DrupalCamp LA 2012

  • 1. Form API 101 Intro to building Forms in Drupal using PHP ! ! presented by Chris Charlton http://xtnd.us
  • 2. Drupal uses PHP Arrays for forms • Easy to Add, Remove, or Alter: • Form fields & their attributes • Validation & Submit handling • Form tag & attributes • Write less code • Reduces markup errors
  • 3. Form Field Types • Text input • File input/upload • Select Lists/Menu/Dropdowns • Checkboxes, Radiobuttons • Lots of types, or make your own!
  • 4. Before we talk Drupal... • <form> HTML tag • PHP code summary • Basics • Arrays
  • 5. <form> <form id="unique-form-id" action="form_action.php">
 First name: <input type="text" name="firstname" />
 Last name: <input type="text" name="lastname" />
 <input type="submit" value="Submit" />
 </form> ! ! !
  • 6. PHP required... but how much? • Basic PHP • Strings & Numbers • Variables • Functions ! ! • Arrays • Keys • Values • Multidimensional/Tree
  • 7. PHP Basics Strings - “this is a string” Numbers - 1234567890 Variables - $long_var_name = 123; Functions - hook_form()
  • 8. PHP Arrays <?php
 // Declare new basic array of numbers up to ten
 $array_of_numbers = array(0, 1, 2, 3, 4, 5, 6, 7, 8);
 $array_of_numbers[] = 9; // Add an array item
 $array_of_numbers[] = 10; // Add another item
 
 //Declare new basic array of strings
 $array_of_strings = array(‘A’, ‘b’, ‘C’, ‘d’, ‘E’); !
  • 9. Mixed Key PHP Array <?php
 // Declare multidimensional array with mixed keys
 $mixed_array = array(
 0 => ‘index zero has this string value’,
 1 => ‘index one has this similar string value’,
 ‘two’ => ‘index two has a string key’,
 ‘three’ => ‘index three also has a string key’,
 4 => ‘index four is a numeric key like index 0 & 1’
 ); !
  • 10. Multidimensional PHP Array <?php
 // Declare multidimensional array with mixed keys
 $multidim_array = array(
 0 => array(
 “person0” => “Jay”,
 “person1” => “Silent Bob”,
 “person2” => “Chris”
 ),
 1 => ‘index one has this similar string value’,
 ‘two’ => ‘index two has a string key’,
 ‘three’ => ‘index three also has a string key’,
 4 => ‘index four is a numeric key like index 0 & 1’
 );
  • 12. Form API - Textfield <?php
 
 $form[‘firstname’] = array(
 ‘#type‘ => ‘textfield’,
 ‘#title‘ => t(‘First name’),
 );
 

  • 13. Form parts you build <form id="simple-form" action="">
 First name: <input type="text" name="firstname" />
 Last name: <input type="text" name="lastname" />
 <input type="submit" value="Submit" />
 </form> ! ! !
  • 14. Same form in PHP using Drupal’s Form API<?php // Simple function returns simple form array
 function simple_form() {
 $form = array();
 $form[‘firstname’] = array(
 ‘#type‘ => ‘textfield’,
 ‘#title‘ => t(‘First name’),
 );
 $form[‘lastname’] = array(
 ‘#type‘ => ‘textfield’,
 ‘#title‘ => t(‘Last name’),
 );
 $form[‘submit’] = array(
 ‘#type‘ => ‘submit’,
 ‘#title‘ => t(‘Submit’),
 );
 return $form;
 } <?php // Call in that custom form
 function custom_form_page() {
 return drupal_get_form(‘simple_form’);
 }
  • 15. Homework #1: Try out all form types
  • 16. Homework #2: Read and learn these...
  • 17. hook_forms() • Hook that lets you declare all known forms within your module and assigns Form ID’s • “hook_” replaced “your_module_name_”
  • 18. hook_form_alter() • The hook allowing you to alter all forms • “hook_” replaced “your_module_name_” • Specific form: hook_form_FORM_ID_alter()
  • 19. Learn more • http://api.drupal.org • http://drupal.org/project/examples • http://drupal.org • http://drupalcampla.com