0
votes

I'd like to make a drupal page with a form. Something like the following, which doesn't render:

function score_table_menu() {

  $items['table'] = array(
    'title' => t('name'),
    'page arguments' => array('table_page'),
    'page arguments' => array('table_form'),
    'description' => t('score table'),
    'type' => MENU_CALLBACK,

  );
  return $items;
}

function table_page(){
$output .= t('Complicated Hello');
$header = stuff;
$rows = stuff;
$output .= theme_table($header, $rows);
return $output;
}

function table_form(){

$stuff_array = array (values);
$form['choice']= array(
    '#type' => 'select',
    '#title' => t('Select Stuff'),
    '#options' => $stuff_array,
  );


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

}

function table_form_validate(){}

function table_form_submit(){
drupal_set_message(t('Submitted'));
}

Is it possible to have half the module render a page and the other half a form? I've written out two page arguments. I don't see any difference between page argument and callback. Also might need to use drupal_get_form() to render the form on the page.

1

1 Answers

0
votes
page callback

is the function that you want this URI to trigger.

page arguments

are any arguments that you want to sent to that function when the callback is called.

Your menu item should look like this:

$items['table'] = array(
  'title' => t('name'),
  'page callback' => 'table_page',
  'description' => t('score table'),
  'type' => MENU_CALLBACK,
);

Or this:

$items['table'] = array(
  'title' => t('name'),
  'page callback' => 'drupal_get_form',
  'page arguments' => array('table_form'),
  'description' => t('score table'),
  'type' => MENU_CALLBACK,
);

In your table_form, you can use other form types to display markup,

$form['table'] = array(
  '#type' => 'markup',
  '#markup' => theme_table($header, $rows),
);

Take a look in the API for a better understanding of hook_menu: http://api.drupal.org/api/drupal/developer%21hooks%21core.php/function/hook_menu/6