Drupal has a powerful, generalized form handing system - the Forms API. If you want a form in your module that is detached from the node concept, you just define an abstract representation of the form and call it from the menu handler directly using drupal_get_form() as the page handler. The form itself gets submitted as normal, and you have complete control over it.

A bare skeleton for the module (Drupal 5) might look like this:

function example_menu($may_cache) {
 $items = array();

 if ($may_cache) {
   $items[] = array(
     'path' => 'example',
     'callback' => 'drupal_get_form',
     'callback arguments' => array('example_form'),
 }

 return $items;
}

function example_form() {
 // define your $form here, reading from the DB as needed.
}

function example_form_validate($form_id, $form_values) {
 // Do stuff with $form_values here and set errors if needed.
}

function example_form_submit($form_id, $form_values) {
 // Do stuff with $form_values here and call DB queries if needed.
}

Now going to /example will display the form defined by example_form(), and
when it's submitted it will first be validated by example_form_validate() and,
if it passes, will get passed to example_form_submit() for whatever saving you
want to do.

For more information, see:
http://api.drupal.org/api/file/developer/topics/forms_api.html/5
http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/5

These API reference pages are essential reading for more advanced understanding of the Forms API.

You can, of course, get ridiculously more complicated than that (especially when you start working with custom theming of forms, which is all sorts of exciting), but that should get you started. For a simple example in a core module, look at the code in the Contact module:

http://api.drupal.org/api/function/contact_mail_page/5
http://api.drupal.org/api/function/contact_mail_page_validate/5
http://api.drupal.org/api/function/contact_mail_page_submit/5

Initially adapted from: http://lists.drupal.org/pipermail/development/2007-December/027942.html

Comments

canen’s picture

There is also a related article on the Lullabot website: Drupal 5: Making forms that display their own results.