(Tutorial) Drupal 5: Making forms that display their own results

Tutorial : Drupal 5: Making forms that display their own results

Drupal's Form API offers advanced features for validation, processing, and (in version 5) multi-part forms that span several pages. Sometimes, though, you need to do something simple: write a form that does nothing but display some formatted information based on the data that was submitted.

Here's a short snippet of code that demonstrates how Drupal 5's new #multistep flag (used for complex, multi-page forms) can also simplify the little problems.

<?php
function multistep_example_form($form_values = NULL) {
 
$form = array();
 
 
// Setting #multistep to true activates some special form
  // handling code for Drupal. First, the FormAPI makes sure
  // that the results of the form's submission are passed back
  // into the builder function when the page loads for the second
  // time. That gives it a chance to build a different version of
  // the form (with additional options, for example). It also
  // does magickal voodoo that keeps validation working properly
  // in those complex multi-page forms. For now, we won't
  // worry about that.
 
 
$form['#multistep'] = TRUE;
 
 
// Setting #redirect to false means that Drupal *won't* attempt
  // to reload a clean copy of the form (by redirecting to the
  // current page, and reloading) when it's submitted. In a multistep
  // form, we want to keep the data around so it can be displayed,
  // or passed on to a subsequent step.
 
 
$form['#redirect'] = FALSE;
 
 
// Remember: in a #multistep form, Drupal makes sure that the
  // $form_values array is passed into this builder function once
  // you submit the form. That gives us a chance to display different
  Continue..

[Read more..]

Courtesy : Lullabot.com