How to pass value generated in the form submit function to another function? I have a question related to drupal 7 form api and module development.

I have a very simple module with a function like this. It gets called by hook_menu when a certain path xyz is visited.

function myview_mainpage() {

  $content .= drupal_render(drupal_get_form('myview_form'));
  $content .= "Some additional stuff here";
  return $content;
}


My form looks like this (it's from the examples module):

function myview_form($form, &amp;$form_state) {
  $form['description'] = array(
    '#type' =&gt; 'item',
    '#title' =&gt; t('A simple form with a submit button'),
  );

  $form['name'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('Name'),
  );

  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; 'Submit',
  );
  return $form;
}


And my submit handler looks like this:

function myview_form_submit($form, &amp;$form_state){

 // I do some sql stuff and generate html content based on the value that was submitted in the form
  $variable = "&lt;div&gt;&lt;h1&gt;Some stuff&lt;/h1&gt;...'; 

}


And now I need to somehow pass the value of $variable to the function myview_mainpage() so it can print it out.
So in a nutshell: User submits a from, some processing is done based on the value submitted and then the results are displayed under the form when it is displayed.

Maybe I could use $form_state['redirect'] to redirect the user to the page xyz but I don't want to send the value of $variable in the address bar of a browser.

Any ideas? This feels like it should be done quite easily but I can't find a way to do it.
You can store that information in the user session. There is always a redirect after a form submission so you need to persist it somewhere because PHP is a stateless.

Simply add your data to $_SESSION['yourmodule'] and then in the mainpage() function check if something is there and display it.

If that information is not temporary and must be there on the next visit too, persist it in the database in a custom table.