home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (form_example.module)

This example Drupal source code file (form_example.module) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

access, arguments, array, callback, description, directory, drupal_get_form, file, form, page, title, translate, true

The form_example.module Drupal example source code

<?php

/**
 * @file
 * Examples demonstrating the Drupal Form API.
 */

/**
 * @defgroup form_example Example: Form API
 * @ingroup examples
 * @{
 * Examples demonstrating the Form API. (drupal 6)
 *
 * This example is part of the Examples for Developers Project which you can download
 * and experiment with here: http://drupal.org/project/examples
 */

require_once('form_example_elements.inc');

/**
 * Implements hook_menu() to set up the URLs (menu entries) for the
 * form examples.
 */
function form_example_menu() {
  $items['examples/form_example'] = array(
    'title' => t('Form Example'),
    'page callback' => 'form_example_info',
    'access callback' => TRUE,
  );
  $items['examples/form_example/tutorial'] = array(
    'title' => t('Tutorial'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_tutorial_1'),
    'access callback' => TRUE,
    'description' => t('A set of ten tutorials'),
    'file' => 'form_example_tutorial.inc',
    'weight' => -20,
  );
  $items['examples/form_example/tutorial/1'] = array(
    'title' => t('#1'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_tutorial_1'),
    'access callback' => TRUE,
    'description' => t('Tutorial 1: Simplest form'),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'file' => 'form_example_tutorial.inc',
  );
  $items['examples/form_example/tutorial/2'] = array(
    'title' => t('#2'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_tutorial_2'),
    'access callback' => TRUE,
    'description' => t('Tutorial 2: Form with a submit button'),
    'type' => MENU_LOCAL_TASK,
    'file' => 'form_example_tutorial.inc',
  );
  $items['examples/form_example/tutorial/3'] = array(
    'title' => t('#3'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_tutorial_3'),
    'access callback' => TRUE,
    'description' => t('Tutorial 3: Fieldsets'),
    'type' => MENU_LOCAL_TASK,
    'file' => 'form_example_tutorial.inc',
  );
  $items['examples/form_example/tutorial/4'] = array(
    'title' => t('#4'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_tutorial_4'),
    'access callback' => TRUE,
    'description' => t('Tutorial 4: Required fields'),
    'type' => MENU_LOCAL_TASK,
    'file' => 'form_example_tutorial.inc',
  );
  $items['examples/form_example/tutorial/5'] = array(
    'title' => t('#5'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_tutorial_5'),
    'access callback' => TRUE,
    'description' => t('Tutorial 5: More element attributes'),
    'type' => MENU_LOCAL_TASK,
    'file' => 'form_example_tutorial.inc',
  );
  $items['examples/form_example/tutorial/6'] = array(
    'title' => t('#6'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_tutorial_6'),
    'access callback' => TRUE,
    'description' => t('Tutorial 6: Form with a validate handler'),
    'type' => MENU_LOCAL_TASK,
    'file' => 'form_example_tutorial.inc',
  );
  $items['examples/form_example/tutorial/7'] = array(
    'title' => t('#7'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_tutorial_7'),
    'access callback' => TRUE,
    'description' => t('Tutorial 7: Form with a submit handler'),
    'type' => MENU_LOCAL_TASK,
    'file' => 'form_example_tutorial.inc',
  );
  $items['examples/form_example/tutorial/8'] = array(
    'title' => t('#8'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_tutorial_8'),
    'access callback' => TRUE,
    'description' => t('Tutorial 8: Form with a reset button'),
    'type' => MENU_LOCAL_TASK,
    'file' => 'form_example_tutorial.inc',
  );
  $items['examples/form_example/tutorial/9'] = array(
    'title' => t('#9'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_tutorial_9'),
    'access callback' => TRUE,
    'description' => t('Tutorial 9: Form with dynamically added new fields'),
    'type' => MENU_LOCAL_TASK,
    'file' => 'form_example_tutorial.inc',
  );
  $items['examples/form_example/tutorial/10'] = array(
    'title' => t('#10'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_tutorial_10'),
    'access callback' => TRUE,
    'description' => t('Tutorial 10: Basic multistep form'),
    'type' => MENU_LOCAL_TASK,
    'file' => 'form_example_tutorial.inc',
    'weight' => 10,
  );
  $items['examples/form_example/tutorial/11'] = array(
    'title' => t('#11'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_tutorial_11'),
    'access callback' => TRUE,
    'description' => t('Tutorial 11: Form with file upload'),
    'type' => MENU_LOCAL_TASK,
    'file' => 'form_example_tutorial.inc',
    'weight' => 11,
  );
  $items['examples/form_example/element_example'] = array(
    'title' => 'Element example',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_element_demo_form'),
    'access callback' => TRUE,
    'file' => 'form_example_elements.inc',
  );

  return $items;
}

/**
 * Simple page callback to give feedback to the user about this example.
 */
function form_example_info() {
  return t('The form example provides <a href="!tutorial_url">tutorial examples</a> tied to the <a href="!handbook_url">handbook</a> and <a href="!element_url">form element examples</a>.', array('!tutorial_url' => url('examples/form_example/tutorial'), '!handbook_url' => 'http://drupal.org/node/262422', '!element_url' => url('examples/form_example/element_example')));
}

/**
 * Implements hook_help() to provide a bit of help.
 */
function form_example_help($path, $arg) {
  switch ($path) {
    case 'examples/form_example/tutorial':
      $help = t('This form example tutorial for Drupal 6 is the code from the <a href="http://drupal.org/node/262422">Handbook 10-step tutorial</a>');
      break;
    case 'examples/form_example/element_example':
      $help = t('The Element Example shows how modules can provide their own Form API element types. Four different element types are demonstrated.');
      break;
  }
  if (!empty($help)) {
    return '<p>' . $help . '</p>';
  }
}


/**
 * Implementation of form_example_elements().
 *
 * To keep the various pieces of the example together, this just returns
 * _form_example_elements().
 */
function form_example_elements() {
  return _form_example_elements();
}
/**
 * Implementation of hook_theme().
 *
 * To keep the various parts of the example together, this actually returns
 * _form_example_element_theme().
 */
function form_example_theme() {
  return _form_example_element_theme();
}

/**
 * @} End of "defgroup form_example".
 */

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal form_example.module source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.