I have for some time now struggled with the database api and have now come near the goal of my database application. I have produced a couple of custom tables and are using the theme function for tables to list the data on the page. What´s left is some pages for deleting old record easily. For this I have tried to use tableselect. I have looked around and trying to do as in the example but I can not make it work.
Here is an example of a small table and the code to list this on a page:
function clubs_page() {
$header = array(
'clubid' => t('Clubid'),
'clubname' => t('Clubname'),
);
$sql = "SELECT * FROM {clubs}";
$result = db_query($sql);
foreach ($result as $dbrow) {
$rows[] = array(
$dbrow->clubid,
$dbrow->clubname,
);
}
$output=theme('table', array('header' => $header, 'rows' => $rows)) . theme('pager');
return $output;
}
This works OK.
To change this to a select page I did this changes:
function clubs_select_form() {
$header = array(
'clubid' => t('Clubid'),
'clubname' => t('Clubname'),
);
$sql = "SELECT * FROM {clubs}";
$result = db_query($sql);
foreach ($result as $dbrow) {
$rows[] = array(
$dbrow->clubid,
$dbrow->clubname,
);
}
$form['clubs_select'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $rows,
'#empty' => t('No clubs.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
Obviously this is wrong. The result is that it flags for empty table and I get this error message:
Notice: Undefined index: #attributes in theme_tableselect() (line 3332 of /home/dev_site/includes/form.inc).
Hope someone can tell me what I have done wrong
Comments
I wrote a tutorial on using
I wrote a tutorial on using tableselect: http://www.jaypan.com/tutorial/themeing-drupal-7-forms-tables-checkboxes...
Contact me to contract me for D7 -> D10/11 migrations.
Thanks,But sorry to say I do
Thanks,
But sorry to say I do not get it work.
I even copy and paste the entire code from your tutorial but I do not get any records and this error message was displayed:
Notice: Undefined index: #attributes in theme_tableselect() (line 3332 of /.../includes/form.inc).
Warning: Missing argument 1 for my_form() in my_form() (line 969 of /.../my.module).
Warning: Missing argument 2 for my_form() in my_form() (line 969 of /.../my.module).
Line 3332 in form.inc is:
Line 969 is:
Is there any missing part in my installation?
I am running Drupal 7.22 and PHP 5.3.25
Always show your code.
Always show your code.
Contact me to contract me for D7 -> D10/11 migrations.
In this case the code
In this case the code (function) is an exact copy of the tutorial you linked to.
A question
Hello,
As asked in the other replies, you need to post your code.
In addition, have to tested your sql. Have you run the sql from the database command line? How many rows and columns are in the database result?
Good Luck :)
I now have installed a clean
I now have installed a clean Drupal 7.22 site with only one custom mudule on it to test the Tutorial code and hopefully learn to understand the concept.
The module called tableselect have two files:
the tableselect.info and the tableselect.module file the code comes here:
It produce an empty table an this this errormessage:
Warning: Missing argument 1 for my_form() in my_form() (line 30 of C:\xampp_old\htdocs\tableselect\sites\all\modules\tableselect\tableselect.module).
Warning: Missing argument 2 for my_form() in my_form() (line 30 of C:\xampp_old\htdocs\tableselect\sites\all\modules\tableselect\tableselect.module).
After a refresh it also generate this error:
Notice: Undefined index: #attributes in theme_tableselect() (line 3332 of C:\xampp_old\htdocs\tableselect\includes\form.inc).
drupal_get_form
drupal_get_form should be the page callback, my_form goes in page arguments.
Array keys
Each row must be indexed on the header keys. Every row in rows must be indexed on a unique id that ends up in the submit function. Next sample assumes clubid is that field:
Also, make sure to change the page callback to drupal_get_form, and pass the form callback as one of the page arguments.
Thank you!I have now managed
Thank you!
I have now managed to get a tableselect working with my club example.
Here is the code that worked: