By davedelong on
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
Your function needs to expect $form_state
So
function page_arg_test_form($arg)should befunction page_arg_test_form($form_state, $arg)That's the clue I needed! I
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
Thanks nevets :)
Thanks nevets :)