Search code examples
phpdrupal-7

calling multiple function in hook menu in drupal


i try to call more than one function in a single hook_menu functionality..but am not getting more than one functionality in the page callback..please help me to solve this..below is my code i try to access getvalue_my_form and getvalue_show in a pagecallback..

     <?php
  global $ema;
  $ema=$_POST['email'];

   drupal_set_message('email:'.$ema);

   function getvalue_menu() {
   $items = array();
    $items['formtest1'] = array(
    'title' => 'valuegetting',
   'page callback' => 'drupal_get_form',
  'page arguments' => array('getvalue_my_form'),
   'access arguments' => array('access content'),
    'type' => MENU_NORMAL_ITEM,
     );

    return $items;
   }
   function getvalue_my_form($form, &$form_state) {

    $form['image_file'] = array(
   '#title' => t('upload Banner:'),
   '#type' => 'file',
    );
   return $form; 
   }
  function getvalue_show()
    {
   $em="hi welcome";
    return $em;

    }

Solution

  • drupal hooking system won't be mixed with general php page coding. Ex.

    you don't write global $ema; etc outside of hook function. If you want to call two functions assuming your module name is getvalue, you probably want to do this.

    function getvalue_menu() {
        $items = array();
        $items['formtest1'] = array(
            'title' => 'valuegetting',
            'page callback' => 'getvalue_two_functions',
            'page arguments' => array(),
            'access arguments' => array('access content'),
            'type' => MENU_NORMAL_ITEM,
         );
    
        return $items;
    }
    
    function getvalue_two_functions() {
        // call first function
        $two_values['first'] = 1;
    
        // call second function
        $two_values['second'] = 2;
    
        return $two_values;
    }
    

    When you type formtest1 in URL, it'll reach getvalue_two_functions(). Form function is just another drupal call, you can call

    drupal_get_form('getvalue_my_form'); 
    

    inside getvalue_two_functions().