3 replies [Last post]
ubuntu@drupal.org's picture
Offline
Joined: 02/28/2008
Juice: 64
Was this information Helpful?

What I am trying to do may fall out of the scope of Tapir. Please let me know if that's the case.

Tables generally deal with data with fixed number of cols and rows. That's what Tapir does.

I love that Tapir can theme a form . With this feature, I can add a column of radio buttons to the table like below. It allows me to handle multiple nodes in my submit function(although I am still trying to figure out an issue with submit function, see my earlier post today)

x c1 c2 c3
x a1 a2 a3
x b1 b2 b3
'submit'

However, is it possible to piggyback some extra form items on to this tapir themed form? e.g. I want to attach an extra row of radio buttons (r1, r2) that don't fit the data table format like the following.

radio r1, r2

x c1 c2 c3
x a1 a2 a3
x b1 b2 b3
'submit'

I tested various hooks and callbacks and didn't see an easy way to do it.

I have a 'hack' idea and want to share it here. Please let me know if it's simply wrong to hack this way. The hack I can see so far is after calling

<?php
$output
= tapir_get_table('my_table', $form).drupal_render($form['submit']);
?>

, parse the $output html, insert the extra form elements. It's brutal force and ugly.

If anyone knows a better way, could you please share it here.

thanks.

half_brick's picture
Offline
Joined: 02/04/2008
Juice: 82
Re: pushing the limit on Tapir

What about having them at the top of the table, but setting the colspan of the cells in order to lay them out like you want? So if it's a 4 column table, but you've only got 2 radios; set your colspan to 2...

I can't remember how to do this off the top of my head, but I think you can pass in an associative array of attributes for a cell at some point.

ubuntu@drupal.org's picture
Offline
Joined: 02/28/2008
Juice: 64
Re: Re: pushing the limit on Tapir

I really don't have a clue what I'm doing, but I got some result, not what I want exactly. But I do see two radio buttons showing below the table. I want to be able to control it, shows either on top or bottom, and also in a row, instead in a column.

see attachment

<?php
function tapirtest_example_6_form() {
  
// i added this radio element in the form
  
$form['ex_row'] = array(
      
'#type' => 'radios',
      
'#options' => array(0=>'r1', 1=>'r2'),
      
'#title'=> 'Select one',
  );
...
}

// then i modified table builder
function tapirtest_example_table_6($op, &$form) {
  switch (
$op) {
...
    case
'data':
   
// i added this line, I don't know what I'm doing here though :(
    // if i use drupal_render($form['ex_row']), then nothing shows up?
   
$data['ex_row'] = drupal_render($form['songs']['ex_row']);
      foreach (
element_children($form['songs']) as $i) {
...
}
?>
AttachmentSize
tapir.gif 26.67 KB
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Re: pushing the limit on Tapir

To get a fuller understanding, you need to know a little about the forms API and its rendering/theming process. For that, I'd recommend starting with the QuickStart guide on http://api.drupal.org.

For now, you can simply modify the theme_tapirtest_example_6_form() function to manually render the radio buttons first before getting the rest of the themed form from the table builder. A mock-up would be something like so...

<?php
function theme_tapirtest_example_6_form($form) {
 
$output = drupal_render($form['ex_row']) . tapir_get_table('tapirtest_example_table_6', $form);
}
?>