[development] submitting and processing a form!

Augustin (Beginner) drupal.beginner at wechange.org
Tue Jul 4 10:23:37 UTC 2006


Hello,

I thought I grocked the new form API, but I have just been pulling my hair 
trying to do something that I thought would be fairly easy.
I guess I still deserve my handle 'beginner' :/ .

In the code below, I create a hook_menu() callback to the function formtest() 
with a form.
I want to be able to print some information according to the form that has 
just been submitted (here, a simple text string), then reprint the form below 
that.
I know that $_POST['op'] is set when I submit (and the process die()s when I 
uncomment that line), but I can't get the information submitted to be 
displayed above the form.

I have tried using the function formtest_submit() but returning a value there 
doesn't get the expected result (it seems it's a path callback).

I have searched the extensive documentation, but all there is is how to build 
a form, not how to process and display the information.

Am I, for the third time this week, missing something obvious and  simple?

Augustin.

<?php
function test_menu() {
  $items[]= array(
    'path' =>'test/formtest',
    'title'=>'test form api',
    'access'=>user_access('administer test'),
    'callback'=>'formtest',
    'type'=>MENU_NORMAL_ITEM
    );
return $items;
}
        
function formtest() {
  $out = 'beginning of output<br />';
  if (isset($_POST['op'])) {
    $out .= 'text entered: ' . $_POST['text']. '<br />'; 
	// the line above doesn't display, no matter what!
    //die();
  }
  $form = array();
  $form['text'] = array(
    '#type' => 'textfield',
    '#title' => t('Enter some text'),
  );
  $form['submit'] = array('#type' => 'submit', '#value' => 
t('Enter'));
  $out .= drupal_get_form('formtest', $form);
  return $out;
}
?>

-- 
http://www.wechange.org/
Because we and the world need to change.
 
http://www.reuniting.info/
Intimate Relationships, peace and harmony in the couple.


More information about the development mailing list