Hello,

I would like to know how to make a form with some of the elements presented in tables.
I have read what's written here http://drupal.org/node/47582
But unfortunately it haven't helped me much since I get an error using the function drupal_render_form().
I've been trying to make it work with drupal_render() but without success so far.
I get errors like:
# warning: Illegal offset type
# warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback
# warning: htmlspecialchars()

What I'm trying to do is a number of radiobuttons and then a table with checkboxes and information and finally (of course) an submitbutton all integrated in on form.

Could somebody please tell me in a simple way how to make this work?
I have been trying forever now and it's getting annoying.

All answers appreciated!!
thank you!

Comments

It would help if you posted your code since it is pretty hard to guess what your code looks like.

..my code for the function in question looks like this and it's far from working..

function fileproject_my_files_table() {
//get fileinfo from db
$fileinfo=fileproject_my_files_db();
//radio-buttons for choosing what to do
$form['choice'] = array(
'#type' => 'radios',
'#options' => array(
t('Delete'),
t('Edit'),
t('Make private'),
t('Make public')),
'#default_value' => 0);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Upload now'
);
drupal_render($form['choice']);
drupal_render($form['submit']);
drupal_get_form($form);
// Make quick search form:
$form['projects'] = array(
  '#type'=> 'checkbox',
  '#options' => $projects,
);
$rows[] = array(
"",
"<b>".'Filname'."</b>",
"<b>".'Private'."</b>",
"<b>".'Size'."</b>",
"<b>".'Download'."</b>"
);
for($i=0; $i<sizeof($fileinfo); $i++)
{
if($fileinfo[$i]->privatefile)
{
$p='yes';
}
else
{
$p='no';
}
$rows[] = array(
//drupal_render($form['projects'])',
'',
$fileinfo[$i]->filename,
$p,
t(sprintf("%01.2f Kb", $fileinfo[$i]->filesize/1000)),
l(
          t("Download"),
          "fileproject/downloading/".$fileinfo[$i]->fpid,
          array(
          "title" => t("Download a file")
          )
     )
);
}
  $output = theme('table', array(), $rows);
  // Render the remainder of the form.
  // This is crucial for proper function.
$output .= drupal_get_form($form);
return $output;
}

You have tried to mash everything in one function and have 4.7 form calls but are using Drupal 5.0.

In Drupal 5 you need code that calls/invokes the form using drupal_get_form(), a function that declares the form fields and in your case another one to theme the form (to get the table layout). If you look at http://drupal.org/node/47582#comment-657822 it shows and example of the function that declares the form fields and the theme function (though I prefer the way you code builds the table than the way the example hardcodes the tags).

You may wish the read the Quick Start Guide for the forms API to learn more about using the forms API.

Thank you very much for taking time and trying to help me out here. It's appreciated I promise.
I've tried to changed my code now into two functions instead of one. The problem now is that I don't know how to get the access to the form-elements. The point having it all in one function was that I wanted to only call the database once. Since the number of rows and the number of checkboxes should be the same (one per row). Do I know need to call the database twice? I guess so.
If somebody could please tell me how to access the formelements and point out again what needs to be changed in my functions I would be very happy.

/**
* Define the my files form
*/
function fileproject_my_files_form() {
//radio-buttons for choosing what to do
$form['choice'] = array(
'#type' => 'radios',
'#options' => array(
t('Delete'),
t('Edit'),
t('Make private'),
t('Make public')),
'#default_value' => 0);
// Make checkboxes
$form['file_checkbox'] = array(
  '#type'=> 'checkbox'
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Upload now'
);
return drupal_get_form($form);
}
/**
* Define the my files table
*/
function fileproject_my_files_form_table(&$form) {
//get fileinfo from db
$fileinfo=fileproject_my_files_db();
//content
$content=$form['choice'];
$rows[] = array(
"",
"<b>".'Filname'."</b>",
"<b>".'Private'."</b>",
"<b>".'Size'."</b>",
"<b>".'Download'."</b>"
);
for($i=0; $i<sizeof($fileinfo); $i++)
{
if($fileinfo[$i]->privatefile)
{
$p='yes';
}
else
{
$p='no';
}
//one row for every item found in the database
$rows[] = array(
//I want to have a checkbox with a value here
$form['file_checkbox'],
$fileinfo[$i]->filename,
$p,
t(sprintf("%01.2f Kb", $fileinfo[$i]->filesize/1000)),
l(
  t("Download"),
  "fileproject/downloading/".$fileinfo[$i]->fpid,
  array(
  "title" => t("Download a file")
  )
)
);
}
  $output = theme('table', array(), $rows);
  $content.=$output;
  $content.=$form['choice'];
// Render the remainder of the form.
  // This is crucial for proper function. 
//$output .= drupal_get_form($form);
return $content;
}