Question: I have custom module, where after form\_submit, i do some calculations, and get result of those calculations in a variable.

After i hit "submit", i can output those calculations with **drupal\_set\_message** , but i would like to format results (array), and print it bellow the submit button. How can i output resulting variable bellow the form or in the form, after submission ?

```
function mymodule_form_submit($form, &$form_state) {

$a=$b+$c;

// on submit, i would like to print/format $a on the reloaded form page

}

```

Thanks!

Answer: 
What you want to do is use something like `$form_state['temporary']` in your `myMod_submit` function. Set `$form_state['temporary'] = $someValue` and rebuild your form. You also want your `myMod_form` function to have a place holder for your data. When the form is loaded, simply check to see if your temp holder is populated. if it is then you know you have a result and display it.

See code below.

```
function myMod_form($form, &$form_state) {

    ...

    if(!empty($form_state['temporary'])) {
        $form['results'] = array(
            '#type'     => 'item',
            '#markup'   => $form_state['temporary'], 
        );
    }

    return $form;
}

function myMod_submit($form_id, &$form_state) {
     ...

     $results = callSomeFunctionToGetResults();

     $form_state['temporary']   = $results;
     $form_state['rebuild']     = TRUE;

     ...
 }

```

i omitted all my code that would populated `$results` but this should get you to where you need to go. 

***quick addition here.*** 

I just realized that you wanted it to go to another page and not the same page. I believe in your `myMod_submit` function you can use `drupal_goto()`. pass it a url and also pass it some options. you can then parse out the options as your values in the other page. See [drupal\_goto](http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_goto/7). however, i haven't tested this option out.
If its a node form you can add an extra form submit handler to get the values Printed if not you probably have a submit function try [`print_r`](http://php.net/manual/en/function.print-r.php) 

As its a form submit you should try [`exit`](http://php.net/manual/en/function.exit.php) OR [`die`](http://php.net/manual/en/function.die.php)

```
function my_module_my_form_submit($form, &$form_state) {
    //drupal_set_message(t('The form has been submitted.'));
    //drupal_set_message('<pre>'.print_r($form_state, 1).'</pre>');
    print_r($form_state, 1);
    die('Check the die !');
}

```

[Basic form with submit handler](http://drupal.org/node/717740)

[How do I add an additional submit handler](https://drupal.stackexchange.com/questions/9436/how-do-i-add-an-additional-submit-handler)