I am working on a form that will allow users to edit a number of nodes at the same time. The fields I'm displaying are for a single field in all the nodes of a specific type. I want to display the form in a table, so far I've been able to get this to work, but for whatever reason, the form's submit function is not getting hit, and I can't figure out why. Here is a snippet of my form
Array
(
[submit1] => Array
(
[#type] => submit
[#value] => Save
)
[8 & Under] => Array
(
[#prefix] => <div><h1>8 & Under</h1>
[#suffix] => </div>
[#tree] => 1
[#theme] => standards_sc_table
[8 & Under-402-409] => Array
(
[#tree] => 1
[Girls-36-A-9329] => Array
(
[#type] => racetime
[#default_value] => 18.09
[#number_decimals] => 2
[#size] => 8
)
[Girls-36-B-9330] => Array
(
[#type] => racetime
[#default_value] => 19.89
[#number_decimals] => 2
[#size] => 8
)
The subsequent form looks like this:
The field is a custom field that I created which works great in other places. This form has about 200 or so fields. When I click submit, the page just reloads and none of the code in the submit function is hit. When I remove the theming and/or several tree levels, the form submits.
Here is the theming code:
function theme_standards_sc_table($vars) {
$element = $vars['element'];
$rows = array();
foreach(element_children($element) as $key) {
$rows[] = array();
$row_count = count($rows) - 1;
foreach(element_children($element[$key]) as $field_key) {
$rows[$row_count][] = array('data' => render($element[$key][$field_key]));
}
}
$header = array('SCY A','SCY B','SCM A','SCM B','EVENT','SCY A','SCY B','SCM A','SCM B');
return theme('table', array('header' => $header, 'rows' => $rows));
}
The code to generate the form is pretty complex, but I'll go ahead and add it in case someone can see something I'm missing.
function standards_create_sc_edit_form() {
/********************************************************************************
* Each row in $standards_data is structured like this
* $standards[$ag][$stroke][$distance][$course][$timestandard][$gender]
* and the value is a stdClass with time and nid properties
********************************************************************************/
drupal_add_css(drupal_get_path('module','standards') . '/admin.css');
$taxonomies = _standards_get_taxonomies();
$form = array(
);
$form['submit1'] = array(
'#type' => 'submit',
'#value' => 'Save'
);
$form['tax'] = array(
'#markup' => '<pre>' . print_r($taxonomies,true) . '</pre>'
);
$courses = array("Short Course Yards","Short Course Meters");
$standards = array("A","B");
$sexes = array("Girls","Boys");
$standards_data = _standards_get_data($courses,$standards);
foreach($standards_data as $ag => $ag_result) {
$form[$ag] = array(
'#prefix' => '<div class="standards_edit_table"><h1>' . $ag . '(' . $ag_key . ')</h1>',
'#suffix' => '</div>',
'#tree' => TRUE,
'#theme' => 'standards_sc_table',
);
foreach($ag_result as $stroke => $stroke_result) {
foreach($stroke_result as $distance => $distance_result) {
$fieldset_title = "{$ag}-{$stroke}-{$distance}";
$form[$ag][$fieldset_title] = array(
'#tree' => true,
);
//create fields for the A and B time standards
$columns = array();
$column_count = 0;
foreach($sexes as $sex) {
foreach($courses as $course) {
foreach($standards as $standard) {
$course_tid = $taxonomies['course']['names'][$course];
$sex_tid = $taxonomies['gender']['names'][$sex];
if(isset($distance_result[$course_tid][$standard])) {
$time = $distance_result[$course_tid][$standard][$sex_tid];
$field_title = "{$sex}-{$course_tid}-{$standard}-" . $time->nid;
$form[$ag][$fieldset_title][$field_title] = array(
'#type' => 'racetime',
'#default_value' => _racetime_integer_to_formatted($time->time,2),
'#number_decimals' => 2,
'#size' => 8,
);
}
}
}
$column_count++;
$form[$ag_key][$fieldset_title]['event'] = array(
'#markup' => $taxonomies['distance']['tids'][$distance] . " " . $taxonomies['stroke']['tids'][$stroke],
);
}
}
}
}
$form['submit2'] = array(
'#type' => 'submit',
'#value' => 'Save'
);
return $form;
}
function standards_create_sc_edit_form_submit($form,&$form_state) {
drupal_set_message("This worked");
drupal_goto('admin/standards');
}