SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & ArraysHenry Osborne
 
Building Data Mapper PHP5
Building Data Mapper PHP5Building Data Mapper PHP5
Building Data Mapper PHP5Vance Lucas
 
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.3Jeremy Coates
 
Advanced Internationalization with Rails
Advanced Internationalization with RailsAdvanced Internationalization with Rails
Advanced Internationalization with RailsClinton Dreisbach
 
PHP Built-in String Validation Functions
PHP Built-in String Validation FunctionsPHP Built-in String Validation Functions
PHP Built-in String Validation FunctionsAung Khant
 
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 cartSelf
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP FunctionsAhmed Swilam
 
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-KjaerCOMMON Europe
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop NotesPamela Fox
 
Defensive Coding Crash Course Tutorial
Defensive Coding Crash Course TutorialDefensive Coding Crash Course Tutorial
Defensive Coding Crash Course TutorialMark Niebergall
 
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_FormJeremy Kendall
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysqldurai arasan
 

Was ist angesagt? (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
 

Ähnlich wie Drupal Form API 101 (PHP) - DrupalCamp LA 2012

PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackUAnshu Prateek
 
03-forms.ppt.pptx
03-forms.ppt.pptx03-forms.ppt.pptx
03-forms.ppt.pptxThắng It
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04Spy Seat
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Michelangelo van Dam
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. wahidullah mudaser
 
php (Hypertext Preprocessor)
php (Hypertext Preprocessor)php (Hypertext Preprocessor)
php (Hypertext Preprocessor)Chandan Das
 
Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)Subhasis Nayak
 
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 3Mohd Harris Ahmad Jaal
 
Working with data.pptx
Working with data.pptxWorking with data.pptx
Working with data.pptxSherinRappai
 
Advancing Your Custom Fields - WordCamp 2014
Advancing Your Custom Fields - WordCamp 2014Advancing Your Custom Fields - WordCamp 2014
Advancing Your Custom Fields - WordCamp 2014Carleton Web Services
 
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...anshkhurana01
 
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 PHPiMasters
 

Ähnlich wie 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
 

Mehr von Chris Charlton

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 2012Chris Charlton
 
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)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 CharltonChris 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 DrushChris Charlton
 
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 CharltonChris 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)Chris Charlton
 
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...Chris Charlton
 
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)Chris Charlton
 
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 CharltonChris Charlton
 
Better Drupal Interaction Design with Flex
Better Drupal Interaction Design with FlexBetter Drupal Interaction Design with Flex
Better Drupal Interaction Design with FlexChris Charlton
 

Mehr von 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
 

Kürzlich hochgeladen

Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
+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
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 

Kürzlich hochgeladen (20)

Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
+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...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

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