• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

The secret of Forms API and hooks

This version was saved 17 years, 10 months ago View current version     Page history
Saved by PBworks
on May 12, 2006 at 8:18:34 am
 

 

  • form elements are nestable (fieldset = container for other form fields)
  • defined as a data strucure
    1. sigil indicates a named parameter
      • #title, #type, #cols, #rows, etc
    2. #required property = "for free" validation
    3. data structure is handed off to drupal_get_form('form_id', $form)
    4. drupal_get_form outputs html-ified form for output

 

  • Form-specific hooks
    • _validate -- gets triggered by function named "(form id here)_validate" - so it's tied to the form id (validate "this form")
      • fooform_validate($form_id, $form_values)
      • check that your data validates the way you wanted
    • _submit -- also defined based on the form_id passed to drupal_get_form()
      • submit hook defines a destination
      • functionality for doing stuff with data defined in the form goes in this hook
    • _alter -- defined by MODULENAME_form_alter()
      • applies to ALL forms
      • allows you to directly modify the structure of a form before display
        • add / hide elements
        • change weights
        • alter properties

 

    • Theming Forms
      • *everhthing* is themeable
      • You can now theme forms individually
      • You can also theme form /elements/ individually
      • theme_formid($form) - automatic ability to customize any form's look
      • use form_render() to display individual elements
      • #theme_ -- allows you to customize a form or a form element
      • provides ability to reuse themes for multiple forms
    • General Markup
      • #type => markup - insert any HTML in a form
      • #prefix and #suffix - wrap something around the element
      • if you don't define a #type, it defaults to markup
      • Forms API Quickstart - [http://drupal.org/node/36050]
      • Forms API Reference - [http://drupal.org/node/36054]
      • Tips & Tricks - [http://drupal.org/node/36900]