I have a simple form that is in a module

; $Id$
name = Form Example
description = Shows how to build a Drupal form.
package = Pro Drupal Development
core = 6.x

the above is the .info file

// $Id$

/**
 * @file
 * Play with the Form API.
 */

/**
 * Implementation of hook_menu().
 */
function formexample_menu() {
  $items['formexample'] = array(
    'title' => 'View the form',
    'page callback' => 'formexample_page',
    'access arguments' => array('access content'),
  );
  return $items;
}

/**
 * Menu callback.
 * Called when user goes to http://example.com/?q=formexample
 */
function formexample_page() {
  $output = t('This page contains our example form.');

  // Return the HTML generated from the $form data structure.
  $output .= drupal_get_form('formexample_nameform');
  return $output;
}

/**
 * Define a form.
 */
function formexample_nameform($form_id, $form_state = NULL) {
  $form_state['formexample']['spam_score'] = 90;
  $form['user_name'] = array(
    '#title' => t('Your Name'),
    '#type' => 'textfield',
    '#description' => t('Please enter your name.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit')
  );
  if (isset($form_state['formexample']['spam_score'])) {
    $form['captcha'] = module_invoke_all('captcha', 'generate', 'Math');
  }
  return $form;
}

/**
 * Validate the form.
 */
function formexample_nameform_validate($form_id, &$form_state) {
  if ($form_state['values']['user_name'] == 'King Kong') {
    // We notify the form API that this field has failed validation.
    form_set_error('user_name',
      t('King Kong is not allowed to use this form.'));
  }
}

/**
 * Handle post-validation form submission.
 */
function formexample_nameform_submit($form_id, $form_state) {
  $name = $form_state['values']['user_name'];
  drupal_set_message(t('Thanks for filling out the form, %name',
    array('%name' => $name)));

}

The code above is a .module file. I dont really understand what it's supposed to do or how it's supposed to work. Do I create a form on a regular page and tne submit it to this? Do I somehow call the form to display it. How does this attach to a regular page that displays a form or am I missing something?

Any help would be appreciated

Comments

vasi1186’s picture

Hi,

Your problem might be here in the form constructor declaration. So, please replace
function formexample_nameform($form_id, $form_state = NULL) {} with function formexample_nameform($form_state = array()) {}

Vasi.