Posted by Edward.H on August 4, 2009 at 8:23am
SOLVED!see my reply for details,thanks for cignex & netman
help!SOS! Could anyone help me out on themeing below dynamic forms within a table and all same delta forms must be within a same <tr> </tr>column,many many thanks in advance.
the table I want:
<table>
<tr>
<td>form[a] [0]</td>
<td>form[b] [0]</td>
<td>form[c] [0]</td>
<td>form[d] [0]</td>
</tr>
<tr>
<td>form[a] [1]</td>
<td>form[b] [1]</td>
<td>form[c] [1]</td>
<td>form[d] [1]</td>
</tr>
<tr>
<td>form[a] [2]</td>
<td>form[b] [2]</td>
<td>form[c] [2]</td>
<td>form[d] [2]</td>
</tr>
.....
</table>codes:
function demo_abcd_form($form_state, &$node){
$delta=0;
for($delta=0;$delta<count($igdata);$delta++){
$form['a'][$delta]=array(
...
);
$form['b'][$delta]=array(
.....
);
$form['c'][$delta]=array(
.....
);
$form['d'][$delta] = array(
.....
);
}
return $form;
}
function demo_nodeapi(&$node, $op, $teaser=FALSE, $page=FALSE ){
......
switch ($op) {
case 'view':
$node->content['demo_form'] = array(
'#type'=>'fieldset',
'#title'=>'demo',
'#value' => '<table style="text-align: left; width: 100%;" border="1"
cellpadding="2" cellspacing="2" ><tbody>'.drupal_get_form('demo_abcd_form',$node).'</tbody-></table>',
'#weight' => -5,
);
break;
}
Comments
you can you theme_form hook
you can you theme_form hook to make a theme for form.
here you will find example http://drupal.org/node/36142
I solved
I'v solved this problem,I use below codes which I learned form the Userplus module. This is a really good example on theming dynamic forms for beginner like me:)
function demo_abcd($form_state, &$node){
$delta=0;
for($delta=0;$delta<count($igdata);$delta++){
$form['test'][$delta] ['a']=array(
...
);
$form['test'][$delta] ['b']=array(
.....
);
$form['test'][$delta] ['c']=array(
.....
);
$form['test'][$delta] ['d']= array(
.....
);
}
return $form;
}
theme_demo_abcd($form){
$header = array('item number','1', '2', '3 ', '4');
foreach (element_children($form['test']) as $delta) {
$gblist = $form['test'][$delta];
unset($row);
$row[] = array('data' => ''. ($delta + 1) .' ', 'class' => 'form-index');
$row[] = drupal_render($gblist['a]);
$row[] = drupal_render($gblist[b']);
$row[] = drupal_render($gblist['c']);
$row[] = drupal_render($gblist['d']);
$rows[] = $row;
}
$output = theme('table', $header, $rows, array('id' => 'test-list'));
$output .= drupal_render($form['form_id']);
$output .= drupal_render($form['form_token']);
return $output;
}
function demo_theme() {
return array(
'demo_abcd' => array(
'arguments' => array('')
),
);
}
http://webmasterclip.com