On 7/4/06, <b class="gmail_sendername">Augustin (Beginner)</b> <<a href="mailto:drupal.beginner@wechange.org">drupal.beginner@wechange.org</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
In the code below, I create a hook_menu() callback to the function formtest()<br>with a form.<br>I want to be able to print some information according to the form that has<br>just been submitted (here, a simple text string), then reprint the form below
<br>that.<br>I know that $_POST['op'] is set when I submit (and the process die()s when I<br>uncomment that line), but I can't get the information submitted to be<br>displayed above the form.<br><br>I have tried using the function formtest_submit() but returning a value there
<br>doesn't get the expected result (it seems it's a path callback).</blockquote><div><br>That's correct.<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have searched the extensive documentation, but all there is is how to build<br>a form, not how to process and display the information.<br><br>Am I, for the third time this week, missing something obvious and simple?</blockquote>
<div><br>You need to save the data somewhere. There are a number of possibiilites:<br>- save it in $_SESSION,<br>- redirect to a path with the text attached to the url),<br>- save it in a variable or other db table,<br>- disable redirecting.
<br>(there may be more options)<br><br>BTW: your data is in $_POST['edit']['text'] not $_POST['text']<br><br>So your example code becomes, if you disable redirects (last option):<br><br></div></div><?php<br>function test_menu($may_cache = FALSE) {
<br> $items = array();<br> $items[] = array(<br> 'path' => 'test/formtest',<br> 'title' => t('Test form api'),<br> 'access' => TRUE,<br> 'callback' => 'test_formtest',<br> 'type' => MENU_NORMAL_ITEM,
<br> );<br> return $items;<br>}<br><br>function test_formtest() {<br> $form = array();<br><br> if (!empty($_POST['edit']['text'])) {<br> $form['entered-text'] = array(<br> '#type' => 'item',<br> '#title' => t('Entered text'),
<br> '#value' => $_POST['edit']['text'],<br> );<br> }<br><br> $form['text'] = array(<br> '#type' => 'textfield',<br> '#title' => t('Enter some text'),<br> );<br> $form['submit'] = array(<br> '#type' => 'submit',
<br> '#value' => t('Enter'),<br> );<br><br> return drupal_get_form('test_formtest', $form);<br>}<br><br>function test_formtest_submit($form_id, $form_values) {<br> return FALSE;<br>}<br>?><br><br>Depending on your case, you may need to test inside _submit() which button is pressed (using $_POST['op']) and redirect to another page depending on the button (eg "Preview" or "Submit").
<br><br>You may prefer to save the data in $_SESSION if you want the data to be available again when they go to the form again, the _submit() then becomes (with some small changes to the form obviosuly):<br><br><?php<br>
function test_formtest_submit($form_id, $form_values) {<br> $_SESSION['test_formtest'] = $form_values;<br>}<br>?><br><br>Hope this helps,<br>Robrecht<br>