hi, i try to add a parameter to admin/config/my_page/my_menu. the page url should be admin/config/my_page/my_menu?get_option=yes like this.

my hoo_menu looks like this,

function my_modul_menu(){	
           $items = array();
	$items['admin/config/my_page'] = array(
		'title' => t('some title'),
		'description' => t('some description'),
		'position' => 'left',
		'weight' => -30,
		'page callback' => 'system_admin_menu_block_page',
		'access arguments' => array('page permission'),
		'file' => 'system.admin.inc',
		'file path' => drupal_get_path('module', 'system'),
  );
  $items['admin/config/my_page/my_menu'] = array(
		'title' => 'some title',
		'description' => t('some desc.'),
		'page callback' => 'my_page_func',
		'access arguments' => array('page permission'),
		'weight' => -10,
  );
return $items;
}
function my_page_func(){
    $output = '';
    
   if($_GET['get_option'] == 'yes'){
     // do something here
     }else{
         $output .= drupal_render(drupal_get_form('my_form'));
     }
    
    return $output;
}
function my_form($form,&$form_state){
   $form_state['redirect'] = 'admin/config/my_page/my_menu?get_option=yes';   
   $form['#submit'] = array(
		'#type' => 'submit',
		'#value' => 'Save',
		
	);
   return $form;
}

how do i do that? please help someone?

Comments

pushpinderchauhan’s picture

In Drupal there is no need to pass parameter like this. hook_menu() gives you a simple way to pass arguments in URL.

Your code should be something like this.

function my_modul_menu(){
     $items = array();
    $items['admin/config/my_page/'] = array(
        'title' => t('some title'),
        'description' => t('some description'),
        'position' => 'left',
        'weight' => -30,
        'page callback' => 'system_admin_menu_block_page',
        'access arguments' => array('page permission'),
        'file' => 'system.admin.inc',
        'file path' => drupal_get_path('module', 'system'),
  );
 
  // Use Wildcards to pass arguments. 
  $items['admin/config/my_page/my_menu/%'] = array(
        'title' => 'some title',
        'description' => t('some desc.'),
        'page callback' => 'my_page_func',
        'page arguments' => array(4), // An array of arguments to pass to the page callback function, with path component substitution.
        'access arguments' => array('page permission'),
        'weight' => -10,
  );
return $items;
}
function my_page_func($get_option = ''){
    $output = '';
   if($get_option == 'yes'){
     // do something here
     }else{
         $output .= drupal_render(drupal_get_form('my_form'));
     }
    return $output;
}
function my_form($form,&$form_state){
   $form_state['redirect'] = 'admin/config/my_page/my_menu/yes';
   $form['#submit'] = array(
        '#type' => 'submit',
        '#value' => 'Save',
    );
   return $form;
}

You can take more idea about this from here.

Pushpinder Rana #pushpinderdrupal
Acquia Certified Drupal Expert

najubudeen’s picture

hi pushpinderrana, i tested your codes. but it doesn't display menu at the configuration page. i have written my codes below.

function pass_url_vars_permission(){
	return array(
		'page permission' => array(
			'title' => 'Accessing page permission',
			'description' => 'page permission desc',
			'restrict access' => TRUE,
		),
	);
}
function pass_url_vars_menu() {
	$items['admin/config/my_page/'] = array(
			'title' => 'my form test',
			'description' => 'practising for form test.',
			'weight' => -30,
			'position' => 'left',
			'page callback' => 'system_admin_menu_block_page',
			'access arguments' => array('page permission'),
			'file' => 'system.admin.inc',
			'file path' => drupal_get_path('module','system'),
		);
	$items['admin/config/my_page/my_menu/%'] = array(
			'title' => 'my menu title',
			'description' => t('some desc.'),
			'page callback' => 'my_pagecallback_func',
			'page arguments' => array(4), // An array of arguments to pass to the page callback function, with path component substitution.
			'access arguments' => array('page permission'),
			'weight' => -10,
	  );

return $items;
}

function my_pagecallback_func($get_option = ''){
    $output = '';
   if($get_option == 'yes'){
     	$output .= 'hi';
     }else{
         $output .= drupal_render(drupal_get_form('my_form'));
     }
    return $output;
}

function my_form($form,&$form_state){
   $form_state['redirect'] = 'admin/config/my_page/my_menu/yes';
   $form['#submit'] = array(
        '#type' => 'submit',
        '#value' => 'Save',
    );
   return $form;
}
pushpinderchauhan’s picture

There is a chance of some TYPO mistake, for menu you need to define parent call back function in correct manner. It should be something like this.

$items['admin/config/my_page/my_menu'] = array(
      'title' => 'my menu title',
      'description' => t('some desc.'),
            'page callback' => 'my_pagecallback_func',
            'page arguments' => array(4), // An array of arguments to pass to the page callback function, with path component substitution.
            'access arguments' => array('page permission'),
            'weight' => -10,
      'type' => MENU_NORMAL_ITEM,
    );

Also following code is not looking fine as you have added redirect option in form without any other fields. I believe you are not sharing your complete code with us so it is looking like this.

function my_form($form,&$form_state){
   $form_state['redirect'] = 'admin/config/my_page/my_menu/yes';
   $form['#submit'] = array(
        '#type' => 'submit',
        '#value' => 'Save',
    );
   return $form;
}

Pushpinder Rana #pushpinderdrupal
Acquia Certified Drupal Expert

najubudeen’s picture

hi pushpinderrana, i have rectified my codes. it works correctly now. Thank you very much for your reply.

function pass_url_vars_permission(){
	return array(
		'page permission' => array(
			'title' => 'Accessing page permission',
			'description' => 'page permission desc',
			'restrict access' => TRUE,
		),
	);
}
function pass_url_vars_menu() {
	$items['admin/config/my_page'] = array(
			'title' => 'my form test',
			'description' => 'practising for form test.',
			'weight' => -30,
			'position' => 'left',
			'page callback' => 'system_admin_menu_block_page',
			'access arguments' => array('page permission'),
			'file' => 'system.admin.inc',
			'file path' => drupal_get_path('module','system'),
			
		);
	$items['admin/config/my_page/my_menu'] = array(
			'title' => 'my menu title',
			'description' => t('some desc.'),
			'page callback' => 'my_pagecallback_func',
			'access arguments' => array('page permission'),
			'weight' => -10,
	  );
	  $items['admin/config/my_page/my_menu/%'] = array(
			'title' => 'some title',
			'page callback' => 'my_pagecallback_func',
			'page arguments' => array(4), 
			'access arguments' => array('page permission'),
			'weight' => -10,
	  );

return $items;
}

function my_pagecallback_func($get_option = ''){
    $output = '';
   if($get_option == 'yes'){
     	$output .= 'hi';
     }else{
         $output .= drupal_render(drupal_get_form('my_form'));
     }
    return $output;
}

function my_form($form,&$form_state){
   $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Save',
    );
   return $form;
}
function my_form_submit($form,&$form_state){
	$form_state['redirect'] = array('admin/config/my_page/my_menu/yes');
}