[development] Forms API Question - Node with table like poll.module

Simon Lindsay simon at dirtbike.ws
Sat Nov 12 00:34:10 UTC 2005


Hello All,

I'm developing some modules to manage my computer business, and to do 
invoice, purchase orders, timesheets etc. I was using a table in the 
form in 4.6.3, but things are different in 4.7.

The code below looks the closert so far, is there a better way to do 
this anybody can recommend? I've looked at the modules that use 
arrays/rows, like poll and system, but they aren't really doing what i'm 
trying to.

Or do I just need to use css in the theme it to get the correct display?

I'm open to suggestions.

TIA

Simon

4.6.3
-------
   $header = array(t('Time'), t('Customer'), t('Comments'));
   $rows = array();
   $count = count($node->timesheet_time);
   if ($count < 5) {
     $count = 5;
   }
   if ($_POST['edit']['timesheet_links_more'] == 1) {
     $count += 5;
   }
   for ($i = 0; $i < $count; $i++) {
     $row = array();
     $row[] = form_textfield('', 'timesheet_time][' . $i, 
$node->timesheet_time[$i], 6, 6);
     $row[] = form_autocomplete('', 'timesheet_customer][' . $i, 
$node->timesheet_customer[$i], 30, 128, 
'contacts/autocomplete_customer', $type);
     $row[] = form_textfield('', 'timesheet_comments][' . $i, 
$node->timesheet_comments[$i], 30, 255);
     //$row[] = form_textarea('', 'timesheet_comments][' . $i, 
$node->timesheet_comments[$i], 20, 2);

     $rows[$i] = $row;
   }

   $output .= form_item(t('Timesheet Entries'), theme('table', $header, 
$rows));

4.7
------

   // If the user pressed the button asking for more rows, add more
   if ($_POST['edit']['timesheet_links_more'] == 1) {
     $count += 5;
   }

   $form['entries'] =
     array(
           '#type' => 'fieldset',
           '#title' => t('Timesheet Entries'),
           '#tree' => TRUE,
           );

   // Now actually display the rows
   for ($i = 0; $i < $count; $i++) {
     $form['entries'][$i] =
       array(
             '#type' => 'fieldset',
             '#tree' => TRUE,
             );
     $form['entries'][$i]['timesheet_time'] =
       array(
             '#type' => 'textfield',
             '#size' => 6,
             '#maxlength' => 6,
             '#default_value' => $node->timesheet_time[$i],
             '#prefix' => '<table><tr><td>',
             '#suffix' => '</td>',
             );

     $form['entries'][$i]['timesheet_customer'] =
       array(
             '#type' => 'textfield',
             '#size' => 30,
             '#maxlength' => 128,
             '#autocomplete_path' => 'customer/autocomplete',
             '#default_value' => $node->timesheet_customer[$i],
             '#prefix' => '<td>',
             '#suffix' => '</td>',
             );

     $form['entries'][$i]['timesheet_comments'] =
       array(
             '#type' => 'textfield',
             '#size' => 30,
             '#maxlength' => 255,
             '#default_value' => $node->timesheet_comments[$i],
             '#prefix' => '<td>',
             '#suffix' => '</td></tr></table>',
             );

   }



More information about the development mailing list