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 my
EntityFieldQueryunder the form like a
View`.
For the moment I created a module with HOOK_menu
:
function statistiques_menu() { $items = array(); $items['statistiques'] = array( 'title' => t('Statistics Page'), 'description' => t('Homepage for statistics'), 'page callback' => '_homepage_for_statistics', //'page arguments' => array('form_example_form'), 'access arguments' => array('access content'), ); return $items; }
A simple form here :
function statistiques_form($form, &$form_state) { $form['age'] = array( '#title' => t('Age'), '#type' => 'textfield', '#required' => TRUE, '#maxlength' => 3, '#size' => 3, '#weight' => 0, ); $form['submit'] = array( '#type' => 'submit', '#validate' => array('statistiques_form_validate'), '#submit' => array('statistiques_form_submit'), '#weight' => 10, '#value' => 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' => array( 'template' => 'statistiques', 'variables' => array(), ), ); } function _homepage_for_statistics(){ global $user; $output = ''; $vartest = 'my var test to template'; $output .= theme('statistiques_template', array( 'vartest' => $vartest, 'form' => drupal_get_form('statistiques_form'), )); return $output; }
My template look like this :
<?php print render($form['age']); ?> <?php print render($form['submit']); ?>
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
Sponsored by SupremePR