Hey everyone,

I'm having an issue with hook_menu, drupal_get_form, and page arguments. I've isolated my issue to the following code:

//in page_arg_test.module:
function page_arg_test_menu() {
  $items = array();
  $items['page_arg_test'] = array(
    'title' => t('Arg test'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('page_arg_test_form', '0'),
    'access arguments' => array(true)
  );
  return $items;
}

function page_arg_test_form($arg) {
  return array(
    'test' => array(
      '#type' => 'textfield',
      '#title' => t('Arg test'),
      '#value' => print_r($arg, true)
    )
  );
}

When I run this, I get a text field (as expected), but instead of having a value of "0" (like should be passed in from 'page arguments' in hook_menu), it has:
Array ( [storage] => [submitted] => [post] => Array ( ) )

Why is it passing in this array instead of "0"? Am I missing something? Is this expected behavior? What can I do to get my string arg passed through?

Thanks,

Dave

Comments

nevets’s picture

So function page_arg_test_form($arg) should be function page_arg_test_form($form_state, $arg)

davedelong’s picture

That's the clue I needed! I hadn't realized that $form_state was also passed to the actual form definition function. I should've paid more attention to the form API changes page.

Thanks, nevets. =)

Dave

marashi’s picture

Thanks nevets :)