Helpers Form Functions

Last modified: February 9, 2009 - 17:06

Functions

countries_select_for_form($title = '', $default_value = NULL, $required = FALSE, $description = '', $multiple = FALSE)

Build a form-structure filled with countries; this can be used in a select list.

  • Calling parameters
  • $title
    the title of the form. Defaults to "Countries" (translated). If provided, it will not be translated.
    $default_value
    the selected country.
    $required
    whether or not a "none" string should be included in the options.
    $description
    optionally provide a description. Is not translated.
    $multiple
    whether or not to allow multiple choices.
  • Return
  • A completed form element ready to be used.

states_select_for_form($title = '', $default_value = NULL, $required = FALSE, $description = '', $multiple = FALSE)

  • Calling parameters
  • $title
    the title of the form. Defaults to "States" (translated). If provided, it will not be translated.
    $default_value
    the selected state.
    $required
    whether or not a "none" string should be included in the options.
    $description
    optionally provide a description. Is not translated.
    $multiple
    whether or not to allow multiple choices.
  • Return
  • A completed form element ready to be used.

month_select_for_form($title = '', $default_value = NULL, $required = FALSE, $description = '', $multiple = FALSE)

  • Calling parameters
  • $title
    the title of the form. Defaults to "Month" (translated). If provided, it will not be translated.
    $default_value
    the selected month.
    $required
    whether or not a "none" string should be included in the options.
    $description
    optionally provide a description. If provided, it will not be translated.
    $multiple
    whether or not to allow multiple choices.
  • Return
  • A completed form element ready to be used.

year_select_for_form($range = 10, $start = 'current', $title = '', $default_value = NULL, $required = FALSE, $description = '', $multiple = FALSE)

  • Calling parameters
  • $range
    The number of years to show from the specified starting year. If this value is negative, then only use the number of years before. If it is positive, then show the number of years before and after.
    $start
    The year to start the list with. If specified (or defaulted) as "current" then, use the current year.
    $title
    The title of the form element. Defaults to "Year" (translated). If provided, it will not be translated.
    $default_value
    The selected year.
    $required
    Whether or not a "none" string should be included in the options.
    $description
    Optionally provide a description. If provided, it will not be translated.
    $multiple
    whether or not to allow multiple choices.
  • Return
  • A completed form element ready to be used.

add_none_to_options($options, $none_string = NULL)

Add a "None" option to an option list.

  • Calling parameters
  • $options
    the options to which you want to append "None."
    $none_string
    Optional string that will be the "none". If you provide this, it will not be translated and not passed trough the theme layer.
  • Return
  • A modified options list with the None option added.

time_form($default, $title, $description = NULL, $format = 24, $include = 'hms', $required = TRUE)

A flexible function to build a time entry form.

  • Calling parameters
  • $default
    the default time stamp for the form.
    $title
    a title for the form section.
    $description
    the description for the time entry.
    $format
    12/24 hour time. Defaults to 24.
    $include
    string indicating the elements to include:
    • h - include an hours element.
    • m - include minutes
    • s - include seconds
    • a - include AM/PM (12 hour format only)

    Note that the fields will be included in the order specified. Default 'hms'.

    $required
    whether or not to make the elements required on the form.
  • Return
  • An array of completed form elements ready to be used.
  • Example
  • $start_time = drupal_get_form('time_form', time(), 'Start', 'Enter a valid start time.', 12, 'hmsa');

    $interval = db_result(db_query('SELECT interval FROM {my_module_table} WHERE task=%d', $taskid));
      $f = drupal_get_form('time_form', $interval, 'Interval', 'Time', 12, 'ms');

 
 

Drupal is a registered trademark of Dries Buytaert.