By drupalshrek on
I am trying to display a form (as a table of rows). I have the table itself displaying and the "Weights" column showing, but none of the other fields/columns are displaying any content. When I look during debug the form structure seems to be filled with data OK. This is a conversion from a D6 form of the statspro module (which I have never seen, so I cannot be 100% sure that it worked in D6)
function statspro_path_aggregator_list_form($form) {
$result = db_query('SELECT
n.spaid, n.name, n.weight
FROM {statspro_path_aggregator} n
ORDER BY n.weight,
n.name,
n.spaid');
$form = array('#theme' => 'statspro_path_aggregator_list_form');
$edit = t('Edit');
$delete = t('Delete');
foreach ($result as $row) {
$spaid = (int) $row->spaid;
$element = _statspro_form_field_name('aggregator', $spaid);
$form[$element] = array('#type' => 'fieldset');
$subelement = _statspro_form_field_name('spaid', $spaid);
$form[$element][$subelement] = array(
'#title' => (int) $row->spaid,
'#type' => 'item',
);
$subelement = _statspro_form_field_name('name', $spaid);
$form[$element][$subelement] = array(
'#title' => $row->name,
'#type' => 'item',
);
$subelement = _statspro_form_field_name('weight', $spaid);
$form[$element][$subelement] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#default_value' => (int) $row->weight,
);
$form[$element]['edit'] = array(
'#type' => 'markup',
'#value' => sprintf(
"<a href='/%s/%u'>%s</a>",
'admin/config/statspro/path_aggregator/edit',
$spaid,
$edit
),
);
$form[$element]['delete'] = array(
'#type' => 'markup',
'#value' => sprintf(
"<a href='/%s/%u'>%s</a>",
'admin/config/statspro/path_aggregator/delete',
$spaid,
$delete
),
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
$form['cancel'] = array(
'#value' => sprintf(
"<a href='/%s'>%s</a>",
'admin/config/statspro/path_aggregator/list',
t('Cancel')
),
);
return $form;
}
Thanks!
Comments
This
This
repeats the pattern
$form[$element][$subelement] = array($form[$element][$subelement]needs to be something like$form[$element][$subelement]['the_field_name']not so sure
Hi nevets,
Thanks for your quick response. It seems to me you are suggesting that the form elements need to be broken down by element name. However, in the code, the $subelement value is calculated afresh before each field, e.g.
So 'the_field_name' is already generated isn't it?
drupalshrek
Code with the problem
I don't seem to be able to attach any files here, so I have added a zip of the module with an explanation where to look here:
http://drupal.org/node/980584#comment-7006818
Thanks for any help on this.
drupalshrek