By jaypan on
This thread is to post a solution, rather than ask a question, in case someone else has the same problem.
$form_state['values'] was empty for me in my submission callback. If I set a default value, the default value was shown as the value, otherwise it was empty.
The problem was as follows. First, my code:
/**
* hook_menu()
**/
function my_module_menu()
{
$menu['my_form'] = array
(
'title' => 'My form',
'page callback' => 'drupal_get_form',
'page arguments' => array('my_page_callback'),
'access callback' => TRUE,
);
return $menu;
}
function my_page_callback()
{
return drupal_get_form('my_form');
}
function my_form($form, &$form_state)
{
// form definition here
}
If you look closely, i am setting the page callback in hook_form to drupal_get_form(), but my page callback function is not a form definition, rather it calls drupal_get_form() itself. This doubling up of drupal_get_form() is what was causing my troubles. Using the following fixed the problem:
/**
* hook_menu()
**/
function my_module_menu()
{
$menu['my_form'] = array
(
'title' => 'My form',
'page callback' => 'drupal_get_form',
'page arguments' => array('my_form'),
'access callback' => TRUE,
);
return $menu;
}
function my_form($form, &$form_state)
{
// form definition here
}
Hopefully this can help someone else if they are having the same issue.
Comments
Thank you!
This did save my day.
Glad I left it here for you
Glad I left it here for you to find!
Contact me to contract me for D7 -> D10/11 migrations.