1. <?php
  2.  
  3. function my_module_menu() {
  4.   $items = array();
  5.   $items['my_module/form'] = array(
  6.     'title' => t('My form'),
  7.     'page callback' => 'my_module_form',
  8.     'access arguments' => array('access content'),
  9.     'description' => t('My form'),
  10.     'type' => MENU_CALLBACK,
  11.   );
  12.   return $items;
  13. }
  14.  
  15. // This function gets called when we visit 'my_module/form' page. It will generate
  16. // a page with our form on it.
  17. function my_module_form() {
  18.  
  19.   // We build the form by calling the form builder function via the
  20.   // drupal_get_form() function which takes the name of our form builder
  21.   // function as an argument. We return the results to display the form.
  22.   return drupal_get_form('my_module_my_form');
  23.  
  24. }
  25.  
  26. // This function is what we call the "form builder". It builds the form.
  27. // Notice it takes one argument, the $form_state
  28. function my_module_my_form($form_state) {
  29.    
  30.     // Here is our first form element. It's a textfield with a label, "Name"
  31.   $form['name'] = array(
  32.     '#type' => 'textfield',
  33.     '#title' => t('Name'),
  34.   );
  35.   return $form;
  36. }