Hi Guys,

I am trying to do this since last 8 hours but could not get. Now i am posting here my Problem.

I want to show my contents of the form like this.

"Select" : "Image" : "status" (it would be the heading of the table)

checkbox : image : 0
checkbox : iamge : 1
checkbox : iamge : 0
checkbox : iamge : 0
checkbox : iamge : 1
..
..
..
submit(button)

The images ares not placed on their places but come at the end of the whole table in a row.
For this i am using this code.

<?php
$content = image_gallery_print_service();
function image_gallery_print_service($type = null)
{
global $user;
$type = new stdClass();
$type->message = t('There is no image');
$form = array();
$print_res = db_query("SELECT * FROM {print_service} where uid=$user->uid");
$total_print_num = db_num_rows($print_res);
if($total_print_num>0)
{
while ($node = db_fetch_object($print_res))
{
$node = node_load($node->nid);
$nodes[$node->nid] = '';
$form['selected'][$node->nid] = array('#type' => 'checkbox');
$form['nid'][$node->nid] = array(
'#type' => 'markup',
'#value' => image_display($node, 'thumbnail'),
'#tree' => true,
);
$form['sticky'][$node->nid] = array('#type' => 'markup', '#value' => t($node->sticky));
} // end of while loop
$form['selected']['#tree'] = TRUE;
$form['name']['#tree'] = TRUE;
$form['sticky']['#tree'] = TRUE;
$form = theme_sample_form($form);
} // end of if for $total_print_num
else
{
$form['results'] = array(
'#type' => 'item',
//'#title' => t('You have not uploaded any image for printing service'),
'#value' => t('You have not uploaded any image for printing service.'),
);
$form= drupal_render($form);
}
return $form;
}
function theme_sample_form($form) {
$output .= drupal_render($form['common']);
$header = array('Select', 'Name', 'Status');
$rows = array();

foreach ($form['selected'] as $nid => $element ) {
$rows[] = array(
drupal_render($form['selected'][$nid]),
drupal_render($form['name'][$nid]),
drupal_render($form['sticky'][$nid])
// Add elements as needed, status, access, etc
);

}
if ( count($rows) ) {
$output .= theme('table', $header, $rows);
}
$output .= drupal_render($form);
return $output;
}

I want help to solve this problem.
Thanks in advance.

Crinch

Comments

mooffie’s picture

$form = theme_sample_form($form);
[...]
$form= drupal_render($form);

That's not how you theme a form. There are plenty of tutorials on Form API.

Try:

$form['#theme'] = 'sample_form';

Next time wrap your code posting in <code>

crinch’s picture

Hi,

After searching alot, i have decided to come back on this forum and try to get help.
My requirement is there is a while loop that takes the values from database and show in the from.
"checkbox" : "image" : "Title"
...
.
.
..
..
Submit

where will be my main form tag in while loop or above while loop, if i keep my form inside the while loop then there will be form repition. As i have mentioned above my code, it display right in my required fashion but does not work submit button even if you go in the page souce, there is no form tag(
). please let me know this.
I have already wasted alot of my time in doing this more than 3 days.
Any help would be appreciated.

Crinch.

crinch’s picture

Hi Guys,

After searching alot, I have got the error in my code.
If you study this example and try to make it run, how you will invoke this code.

function theme_test_form($form) {
  $output = '';
  $output .= drupal_render($form['name']);
  $output .= '<div class="foo">';
  $output .= drupal_render($form['access']);
  $output .= '<div class="bar">';
  $output .= drupal_render($form['details']);
  $output .= '</div></div>';
  $output .= drupal_render($form);
  return $output;
}

...............How you will call this function. If you call this function like this.

function test_page() {
  $drupal = drupal_get_form('test_form');
  $form['#theme'] = 'test_form';
  return $form;
}

.........You will get wrong form tag like this
tform action=.......................>
and this form does not work but the contents of this form come in row fashion.

I only want to know how we will call "theme_test_form()" function for our form.

Waiting for your help.
Thanks.
Crinch