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

a6hiji7’s picture

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.

jorje29’s picture

Thank you very much for your reply Abhijit. Your solution doesn't work for me but I found out that the code below does :

<?php

function mymodule_menu() {

$items['manager/addleagues'] = array(
    'title' => 'Add Team',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('mymodule_addteams_form'),
    'access callback' => true,
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => 0,
    );

}

function mymodule_addteams_form() {  
  
    $form['title'] = array(
    '#type' => 'textfield',
    '#title' => 'Add Team',
    '#description' => t('Give a name to your team'),
    );

  return $form;

}

?>