Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By jorje29 on
How can I add forms into tabs created by hook menu ? is it possible ?
I have the code below and I want to include a form in every tab
<?php
function demo_menu() {
$items['manager'] = array(
'page callback' => 'manager_overview',
'access callback' => true,
'type' => MENU_NORMAL_ITEM,
);
$items['manager/addleagues'] = array(
'title' => 'Add League',
'page callback' => 'manager_addleagues',
'access callback' => true,
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
$items['manager/addteams'] = array(
'title' => 'Add Teams',
'page callback' => 'manager_addteams',
'access callback' => true,
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items['manager/addplayers'] = array(
'title' => 'Add Players',
'page callback' => 'manager_addplayers',
'access callback' => true,
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
$items['manager/schedule'] = array(
'title' => 'Create Schedule',
'page callback' => 'manager_schedule',
'access callback' => true,
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);
$items['manager/settings'] = array(
'title' => 'Settings',
'page callback' => 'manager_settings',
'access callback' => true,
'type' => MENU_LOCAL_TASK,
'weight' => 4,
);
?>
Comments
You can do it
Just call drupal_get_form in your page callback function. For example if your page callback is manager_addleagues then you can do the following
function manager_addleagues() {
$content = drupal_get_form('manager_addleagues_form');
return $content;
}
Then define manager_addleagues_form -
function manager_addleagues_form() {
$form = array();
$form['form_field1'] = array(
'#type' => 'textfield',
'#title' => t('Form Field Label'),
'#description' => t('Form field description'),
'#default_value' => '',
'#required' => TRUE,
);
return $form;
}
etc.....
That should give you the idea I hope.
Thank you very much for your
Thank you very much for your reply Abhijit. Your solution doesn't work for me but I found out that the code below does :