Create a form programmatically and display result on template I'm trying to create a simple page with a form.
With the different filled fields I want to execute different EntityFieldQuery in the HOOK_form_submit. To finish I want to display the result of myEntityFieldQueryunder the form like aView`. 

For the moment I created a module with HOOK_menu :

function statistiques_menu() {
    $items = array();

    $items['statistiques'] = array(
        'title' =&gt; t('Statistics Page'),
        'description' =&gt; t('Homepage for statistics'),
        'page callback' =&gt; '_homepage_for_statistics',
        //'page arguments' =&gt; array('form_example_form'),
        'access arguments' =&gt; array('access content'),
    );

    return $items;
}


A simple form here : 

function statistiques_form($form, &amp;$form_state) {
    $form['age'] = array(
        '#title' =&gt; t('Age'),
        '#type' =&gt; 'textfield',
        '#required' =&gt; TRUE,
        '#maxlength' =&gt; 3,
        '#size' =&gt; 3,
        '#weight' =&gt; 0,
    );

    $form['submit'] = array(
        '#type' =&gt; 'submit',
        '#validate' =&gt; array('statistiques_form_validate'),
        '#submit' =&gt; array('statistiques_form_submit'),
        '#weight' =&gt; 10,
        '#value' =&gt; t('Click Here!'),
    );

    return $form;
}


I have two functions statistiques_form_validate and statistiques_form_submit under hook_form

Then i send my form and others vars to my template like this :

function statistiques_theme() {
    return array(
        'statistiques_template' =&gt; array(
            'template' =&gt; 'statistiques',
            'variables' =&gt; array(),
        ),
    );
}

function _homepage_for_statistics(){
    global $user;

    $output = '';
    $vartest = 'my var test to template';

    $output .= theme('statistiques_template', array(
        'vartest' =&gt; $vartest,
        'form' =&gt; drupal_get_form('statistiques_form'),
    ));

    return $output;
}


My template look like this :

&lt;?php print render($form['age']); ?&gt;
&lt;?php print render($form['submit']); ?&gt;


I tried Example module, but this case isn't on this module. There is some cases which are close to my problem, after submit the form data are sent to flash message.

With my code the form doesn't work, I can't submit the form but I think it's a small problem... my real problem will come when I will need to display the result of my form validation to my template under the form or on another template. How can do that ?

Thanks
I recommend adding the results of the query to the form markup-like:

$form['something'] = array(
  '#theme' =&gt; 'statistiques_template',
  '#vartest' =&gt; $vartest,
);


is equivalent to theme('statistiques_template', array('vartest' =&gt; $vartest)) -- the theme system will remove the # from the variable names if #theme is set.

But, of course, you can add the form to the page build as well, see how comment_reply does it:

  $build['comment_node'] = node_view($node);
  $build['comment_form'] = drupal_get_form("comment_node_{$node-&gt;type}_form", (object) $edit);


If coding in Drupal 7, forget direct theme calls, strings and the . operator. Work with render arrays instead. It's also a good preparation for Drupal 8 where concatenating strings leads to double escape bugs.