1

I created a block with a form (elemnts: textfield and submit). Also have a page created by the hook_menu. I want that when you click on submit in block, the value from textfield transmitted to a page that is created using the hook_menu and show this page with data from textfield. In the future I plan to transfer some text in the html markup or array.

0

Read about hook_menu and wildcards. Here is an example:

function my_form($form, &$form_state) {
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => 'Name',
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Ok',
  );

  return $form;
}


function my_form_submit($form, &$form_state) {
  $form_state['redirect'] = 'path/' . $form_state['values']['name'];
}

function MODULE_menu() {
  $items['path/%'] = array(
    'title' => 'TTITLE',
    'page callback' => 'my_page_callback',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function my_page_callback($var) {
 return 'HELLO ' . $var;
}
| improve this answer | |
  • Thank you. A new page opens when you click on the submit. However, instead of the value of the textfield just says Arrey. If use return 'HELLO ' . $var['values']['name']; CMS shows an error that no value "values". – user25795 Jan 29 '14 at 8:01
  • @user25795 This is just an example how to use hook_menu and pass values to that page.. And there can not be $var['values'] array in menu callback.. In your case it can be different.. – xurshid29 Jan 29 '14 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.