For me, the following example doesn't work (4.7 rc3). Could someone explain what I'm doing wrong?
Thank you in advance.

function example_form($example = '') {
  $form['example'] = array(
    '#type' => 'textfield',
    '#title' => t('example'),
    '#default_value' => $example,
    '#size' => 20,
    '#maxlength' => 1024,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Verify'),
  );
  
  $form['#method'] = 'post';
  $form['#action'] = url('example');
  
  return drupal_get_form('example_form', $form);
}

function _example_all() {
  $edit = $_POST['example'];
  
  $example = isset($edit['example'])? trim($edit['example']): '';
  
  $output = example_form($example) . '<br /> example:' .  $example;

  return $output;
}

function example_help($section = '') {
  $output = '';

  switch ($section) {
    case 'admin/modules#description':
      $output = t('Example module.');
       break;
  }
  
  return $output;
}

function example_perm() {
  return array('execute example module');
}

function example_menu($may_cache) {
  $items = array();
  
  if($may_cache)
  {
    $items[] = array('path' => 'example',
      'title' => t('example module'),
      'callback' => '_example_all',
      'access' => user_access('execute example module'),
      'type' => MENU_SUGGESTED_ITEM);
  }

  return $items;
}

Comments

he_who_shall_not_be_named’s picture

typo error: must be:

  $edit = $_POST['edit'];

Also, It has a very strange behavior

this code:

print("ex1=$example");
$output = example_form($example) . '<br /> example:' .  $example;

prints out ex1=blabla (but headers already sent warning, if blabla is not entered this warning doesn't appear but ex1= yes (?!))

and

$output = example_form($example) . '<br /> example:' .  $example;
print("ex1=$example");

prints out ex1= (nothing) when blabla is entered in the form.

It is scary.

he_who_shall_not_be_named’s picture

So the $example variable is cleared after the an example_form() call.
I wrote this module to figure out why my converted (and simplified) modules, from Drupal 4.6) doesn't work.

he_who_shall_not_be_named’s picture