By FuriousGeorge on
I'm trying to update my module for D^ and now for some reason, my module's submit handler function is being ignored. After I click submit, the page basically reloads. I'm not sure why this is the case.
<?php
function InventoryChecker_help($section='')
{
$output = '';
switch ($section)
{
case "admin/help#InventoryChecker":
$output = '<p>'. t("Cancel online Listings that are no longer in stock") . '</p>';
break;
}
return $output;
}
function InventoryChecker_perm()
{
return array('access InventoryChecker content');
}
function checker_form($form_values = NULL)
{
$form['header'] = array
(
'#type' => 'value',
'#value' => array
(
array('data' => t('ItemID')),
array('data' => t('Title')),
array('data' => t('End?')),
)
);
$online = Get_Online_Listigs();
foreach ($online as $key => $value)
{
$form['Items'][$key] = array
(
'#type' => 'markup',
'#value' => check_plain($key)
);
$form['Titles'][$key] = array
(
'#type' => 'markup',
'#value' => check_plain($value[Title])
);
$form['End'][$key] = array
(
'#type' => 'checkbox',
'#return_value' => $key,
);
}
$form['submit'] = array
(
'#type' => 'submit',
'#value' => 'End',
);
//$form['#validate'][] = 'checker_validate';
$form['#theme'] = 'checker_form';
return $form;
}
function theme_checker_form($form)
{
foreach (element_children($form['Items']) as $key)
{
$row = array();
$row['data'][1] = drupal_render($form['Items'][$key]);
$row['data'][2] = drupal_render($form['Titles'][$key]);
$row['data'][3] = drupal_render($form['End'][$key]);
$rows[] = $row;
}
$output = theme('table', $form['header']['#value'], $rows);
$output .= drupal_render($form['submit']);
return $output;
}
function InventoryChecker_theme()
{
return array
(
'checker_form' => array
(
'arguments' => array('form' => NULL)
),
);
}
function checker_form_submit($form_id, &$form_state)
{
echo "GOT HERE!"
return;
}
function InventoryChecker_block($op = 'list', $delta = 0, $edit = array())
{
// listing of blocks, such as on the admin/block page
switch ($op)
{
case 'list':
$block[0]["info"] = t('Inventory Checker');
return $block;
case 'configure':
return '$block';
case 'view': default:
$block['subject'] = 'InventoryChecker';
$block['content'] = drupal_get_form('checker_form');
return $block;
}
}
?>
Any help is much appreciated.
Comments
Changes
As per a suggestion in IRC, I removed this line, as I was told it wasn't necessary:
//$form['#theme'] = 'checker_form';...and I added these as I was told it was...
...I was also told the default submit handler didnt need to be specified, but in either case the problem remains the same. The page reloads on submit, but the submit handler function isnt called, and the form is simply redisplayed.
Also, I stuck the following code in line 386 of forms.inc
var_dump($form_state);When the form builds it returns:
array(3) { ["storage"]=> NULL ["submitted"]=> bool(false) ["values"]=> array(0) { } } array(3) { ["storage"]=> NULL ["submitted"]=> bool(false) ["values"]=> array(0) { } }...and after I click some boxes and submit, it returns:
array(3) { ["storage"]=> NULL ["submitted"]=> bool(false) ["values"]=> array(0) { } } array(3) { ["storage"]=> NULL ["submitted"]=> bool(false) ["values"]=> array(0) { } }..obviously, this can't be right.
SOLVED
This line...
$output .= drupal_render($form[''submit]);...should have been.
$output .= drupal_render($form);