Download - Drupal Course 2013 - Form API
![Page 1: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/1.jpg)
Form APIAttila Cs. NagyMarch 14, 2013
Tuesday, March 26, 13
![Page 2: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/2.jpg)
HTML form tagTuesday, March 26, 13
![Page 3: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/3.jpg)
form tag
• <input>
• <textarea>
• <button>
• <select>
• <option>
• ...
Tuesday, March 26, 13
![Page 4: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/4.jpg)
Why are we loving APIs?
Tuesday, March 26, 13
![Page 5: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/5.jpg)
API
• Reusability
• Standard solutions
• Encapsulation
• Connection point
Tuesday, March 26, 13
![Page 6: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/6.jpg)
hook system
Tuesday, March 26, 13
![Page 7: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/7.jpg)
Tuesday, March 26, 13
![Page 8: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/8.jpg)
module foo
Tuesday, March 26, 13
![Page 9: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/9.jpg)
module foo
hook_bar
Tuesday, March 26, 13
![Page 10: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/10.jpg)
module foo
function foo_bar() {
hook_bar
Tuesday, March 26, 13
![Page 11: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/11.jpg)
Form APIhttp://api.drupal.org/api/drupal/developer%21topics
%21forms_api_reference.html/7
Tuesday, March 26, 13
![Page 12: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/12.jpg)
Form API
• Generate HTML
• Handle security issues
• Validation
• Ajax
• States
Tuesday, March 26, 13
![Page 13: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/13.jpg)
Form APITuesday, March 26, 13
![Page 14: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/14.jpg)
Examples moduleform_examplehttp://drupal.org/project/examples
Tuesday, March 26, 13
![Page 15: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/15.jpg)
How does it work?Tuesday, March 26, 13
![Page 16: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/16.jpg)
hook_menuhttp://api.drupal.org/api/drupal/modules%21system
%21system.api.php/function/hook_menu/7
Tuesday, March 26, 13
![Page 17: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/17.jpg)
drupal_get_form($form_id);http://api.drupal.org/api/drupal/includes%21form.inc/
function/drupal_get_form/7
Tuesday, March 26, 13
![Page 18: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/18.jpg)
$form_stateTuesday, March 26, 13
![Page 19: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/19.jpg)
Tuesday, March 26, 13
![Page 20: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/20.jpg)
Validation
Tuesday, March 26, 13
![Page 21: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/21.jpg)
Validation
$form_id_validate($form, &$form_state) {
Tuesday, March 26, 13
![Page 22: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/22.jpg)
#element_validateTuesday, March 26, 13
![Page 23: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/23.jpg)
submit handlingTuesday, March 26, 13
![Page 24: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/24.jpg)
$form_id_submit($form, &$form_state) {
Tuesday, March 26, 13
![Page 25: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/25.jpg)
hook_form_alterhttp://api.drupal.org/api/drupal/modules%21system
%21system.api.php/function/hook_form_alter/7
Tuesday, March 26, 13
![Page 26: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/26.jpg)
States APIhttp://api.drupal.org/api/examples/form_example
%21form_example_states.inc/function/
Tuesday, March 26, 13
![Page 27: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/27.jpg)
system_settings_formhttp://api.drupal.org/api/drupal/modules!system!system.module/function/system_settings_form/7
Tuesday, March 26, 13
![Page 28: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/28.jpg)
hook_element_infohttp://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_element_info/7
Tuesday, March 26, 13
![Page 29: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/29.jpg)
Questions?
Tuesday, March 26, 13
![Page 30: Drupal Course 2013 - Form API](https://reader033.vdocuments.net/reader033/viewer/2022051313/54807f545806b5ea5e8b4a31/html5/thumbnails/30.jpg)
Tuesday, March 26, 13