0
Forms in Drupal     Oleksandr Masovets    E-mail: krasnyj@neformat.com.ua                  Skype: krasnyjdirex
Gold Sponsor ofDrupalCamp Kyiv 2011
Silver Sponsors ofDrupalCamp Kyiv 2011
Working with forms• Form    – Render    – System form•   Form alter•   Form validation•   Form submit•   Destination (redi...
FormForm call function: drupal_get_form($form_id);•$form_id - the unique string identifying the desired form. If afunction...
Form elements
Form element structureRequired parameters:$form[‘element name’] = array (   ‘#type’ = ‘element type’,);Every element autom...
AhahAjax callback for an            element• Using ‘#ahah’(D6) or ‘#ajax’(D7)  attributes to builds a form element with  a...
Theming forms• Adding #theme attributes to the form  and/or elements.• Including any markup directly as an  element in the...
Form alterPerform alterations before a form is rendered:hook_form_alter(&$form, &$form_state, $form_id);                  ...
Form validation• Adding ‘#validate’ attribute (an array with list of  custom validation functions) to the form.• Adding  ‘...
Form submit and redirect• Adding ‘#submit’ attribute (an array with list of custom  submit functions) to the form.• Using ...
Links• http://api.drupal.org• http://api.drupal.org/api/drupal/develope  r--topics--forms_api_reference.html/• http://drup...
Forms in Drupal     Oleksandr Masovets    E-mail: krasnyj@neformat.com.ua                  Skype: krasnyjdirex
Upcoming SlideShare
Loading in...5
×

Oleksandr Masovets. Forms in Drupal. Drupal Camp Kyiv 2011

1,570

Published on

Доклад познакомит начинающих друпалеров с идеологией, архитектурой и основами работы с формами в Drupal.
<ul>
<li> элементы форм</li>
<li> валидация форм</li>
<li> действия (CallBack) форм</li>
<li> ahah действия (CallBack) форм</li>
<li> рендер форм</li>
<li> различия между Form API в Drupal 6 и 7</li>
<li> использование форм в собственных модулях</li>
<li> tips and tricks</li>
</ul>

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,570
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Oleksandr Masovets. Forms in Drupal. Drupal Camp Kyiv 2011"

  1. 1. Forms in Drupal Oleksandr Masovets E-mail: krasnyj@neformat.com.ua Skype: krasnyjdirex
  2. 2. Gold Sponsor ofDrupalCamp Kyiv 2011
  3. 3. Silver Sponsors ofDrupalCamp Kyiv 2011
  4. 4. Working with forms• Form – Render – System form• Form alter• Form validation• Form submit• Destination (redirect)
  5. 5. FormForm call function: drupal_get_form($form_id);•$form_id - the unique string identifying the desired form. If afunction with that name exists, it is called to build the form array.drupal_get_form() does the following:•Starts the entire form-building process by getting the $form fromthe builder function.•Translates the $form[name] items into actual form elements.•Performs any validation and "clean-up" that needs to be done, andcalls custom validation functions if declared.•Submits the form if a submit function is declared, and the form hasbeen submitted.•Calls any custom theming functions that have been declared.•Returns an HTML string which contains the actual form.
  6. 6. Form elements
  7. 7. Form element structureRequired parameters:$form[‘element name’] = array ( ‘#type’ = ‘element type’,);Every element automatically has these default values:•#description = NULL•#attributes = array()•#required = FALSE•#tree = FALSE•#parents = array()
  8. 8. AhahAjax callback for an element• Using ‘#ahah’(D6) or ‘#ajax’(D7) attributes to builds a form element with a set of #ahah#ajax properties.• Using ‘#ajax[‘callback’]’(D7) or ‘#ahah[‘path’]’(D6)#ajax[‘path’]’(D7) to locate ajax function.• Using additional ahahajax options to change behavior of the form element.
  9. 9. Theming forms• Adding #theme attributes to the form and/or elements.• Including any markup directly as an element in the $form array.• Break out any markup into a separate theme function.
  10. 10. Form alterPerform alterations before a form is rendered:hook_form_alter(&$form, &$form_state, $form_id); ORhook_form_FORM_ID_alter(&$form, &$form_state);
  11. 11. Form validation• Adding ‘#validate’ attribute (an array with list of custom validation functions) to the form.• Adding  ‘#element_validate’ attributes (an array with list of custom validation functions) to the form elements.• Using myform_validation($form, &$form_state) function.• The validation functions must use form_error() or form_set_error() functions to flag the element as having an error if the validation fails.
  12. 12. Form submit and redirect• Adding ‘#submit’ attribute (an array with list of custom submit functions) to the form.• Using myform_submit($form, &$form_state) function.• To determine where the user should be sent after the form is processed, the _submit function can place a path or URL in $form_state[redirect] which will be the target of a drupal_goto.• Every form is redirected after a submit. If nothing stored in $form_state[redirect], the form will simply be redirected to itself after a submit.
  13. 13. Links• http://api.drupal.org• http://api.drupal.org/api/drupal/develope r--topics--forms_api_reference.html/• http://drupal.org/node/751826
  14. 14. Forms in Drupal Oleksandr Masovets E-mail: krasnyj@neformat.com.ua Skype: krasnyjdirex
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×