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.
A simple solution to access variables outside the function in other function is to make the scope of the variable as [global](http://php.net/manual/en/language.variables.scope.php#language.variables.scope.global).

```
function mymodule_form_submit($form, &$form_state) {
  global $a;
  $a=$b+$c;    
}

```

And on submit, in other function you can access this variable by something like:

```
function some_page_load_function() {
  global $a;
  //print/format $a according to requirement.
}

```

I've written the function name to be `some_page_load_function`, as I'm not sure about the function you're wishing to access the value; as you also mentioned that this module might be a part of admin region.