menu - How do i get the data?(Drupal 6.x) -
i have form accepts user’s input. is, base on user input, i’d retrieve data , display user.
so far, have implemented hook_menu , registered respective url of form, , implemented submit function referred “#submit” attribute of submit button. i’ve implemented data retrieval code , works great.
here’s problem – don’t know how display retrieved data. i’ve tried several approaches in attempt find solution.
first, theme function, hoping printing return value of display data. second, setting “#action” element of form array newly registered url, thought using same url form cause drupal return form instead , not data. so, creates static variable , stores retrieved data in it;this done inside submit function way. when checked variable inside menu callback, variable not set.
to summarize problem, form has different access url form submit, such as
form url – http://....?q=mymodule/form submit url (value of ”#action”) – http://....?q=mymodule/execute
, , data i’ve set inside submit function static variable not available in menu callback. how make data available?
here’s part of code -
static $retrieved_data; function mymodule_menu() { $command = array(); $command['mymodule/form'] = array( 'title' => 'user input', 'page callback' => 'response', 'page arguments' => array('form'), 'access arguments' => array('access content'), 'type' => menu_callback, ); $command['mymodule/execute'] = array( 'title' => 'search', 'page callback' => 'response', 'page arguments' => array('execute'), 'access arguments' => array('access content'), 'type' => menu_callback, ); return $command; } function _response($parequest){ switch($parequest){ case "form": return drupal_get_form("_myform"); break; case "execute": return $retrieved_data; break; } } function _myform(&$form_state) { $form['#action'] = url($base_path)."?mymodule/execute"; ..... $form['submit'] = array( '#type' => 'submit', '#value' => t('submit'), '#submit' => array('_data_retrieve'), ); return $form; } function _data_retrieve($form, &$form_state){ /*data retrieval code*/ ........................ $retrieved_data = db_fetch_object($result); }
thanks bunch
your method seems bit complicated there. when make systems form, tend way. in mymodule_menu()
change 'page arguments' => array('form'),
'page arguments' => array('name_of_form_function'),
name_of_form_function _myform in case. rename mymodule_myformname.
then create function:
mymodule_myformname_submit($form, &$state) { // enter code here save data form stored in $state // database sql query or node_save($node) if // creating node. }
after can retrieve data database in _data_retrieve function , call on page want retrieve data.
Comments
Post a Comment