Code sample #1:

This is a very basic form which will be expanded upon in the upcoming code samples.


/** 
 * This function defines the URL to the page created etc.
 * See http://api.drupal.org/api/function/hook_menu/6
 */
function my_module_menu() {
  $items = array();
  $items['my_module/form'] = array(
    'title' => 'My form',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('my_module_my_form'),
    'access arguments' => array('access content'),
    'description' => 'My form',
    'type' => MENU_CALLBACK,
  );
  return $items;
}


/**
 * This function gets called in the browser address bar for: 
 * "http://yourhost/my_module/form" or 
 * "http://yourhost/?q=my_module/form". It will generate
 * a page with this form on it.
 * This function is called the "form builder". It builds the form.
 */
function my_module_my_form($form, &$form_state) {
	
	// This is the first form element. It's a textfield with a label, "Name"
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
  );
  return $form;
}

Note: Do not include a last PHP block endings "?>" in modules, as it will "break" Drupal. See: Drupal coding standards

Remember:In order to access your page, you must type the following in the browser address bar: http://yoursite_site_url/?q=my_module/form or http://yoursite_site_url/my_module/form depending on your configuration.

If you do not do this, you will not be able to access your form!