table form form definition


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function mymodule_payment_tracker_form($foo_id) {
  2. $foos = foo_get_foos($foo_id);
  3. $bars = bar_get_bars($bar_id);
  4.  
  5. if (count($foos) > 0) {
  6. // Create the table header.
  7. $form['header'][]['#value'] = t('Foos');
  8. foreach ($bars as $bar_id => $bar_name) {
  9. $form['header'][]['#value'] = $bar_name;
  10. }
  11.  
  12. // Create the rows.
  13. foreach ($foos as $foo_id => $foo_name) {
  14. $row = array();
  15.  
  16. $row['firstcol']['#value'] = $foo_name;
  17. foreach ($bars as $bar_id => $bar_name) {
  18. $row['payments']['#tree'] = TRUE;
  19. $row['payments'][$foo_id][] = array(
  20. 'paid' => array('#type' => 'checkbox', '#default_value' => $bars[$foo_id],
  21. );
  22. }
  23.  
  24. $form['rows'][] = $row;
  25. }
  26.  
  27. // Create a heading.
  28. $form['heading']['#value'] = '<h3>'. t('Payment tracker for foo.') .'</h3>';
  29.  
  30. $form['submit'] = array(
  31. '#type' => 'submit',
  32. '#value' => t('Save'),
  33. );
  34. }
  35. else {
  36. $form['empty']['#value'] = '<p class="foo-empty">'. t('No foos found.') .'</p>';
  37. }
  38.  
  39. $form['#theme'] = 'mymodule_table_form';
  40.  
  41. return $form;
  42. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.