1

I got a Form and a Table displayed on the same page. The weird thing is that when the form is submitted and the page are reloaded (after doing a database SELECT) with $_POST values, the table is not showing....why?

Here is the code (suppose $tabb2 have correct table data):

<?php 

function collabinc_menu($may_cache) {
  $items = array();
  $items['admin/reporting/report_details2'] = array(
    'title' => 'Report: User details by stores',
    'access arguments' => array('access content'),
    'page callback' => 'say_report_details2',
    'type' => MENU_CALLBACK,
  );  
  return $items;
}

function say_report_details2($values = array()) {
  $output = "";

  if (isset ($_POST['search'])) {
     $output = theme("table", $tabb2);
  }

  $build['content'] = array(
    'this_does_not_matter_too_much2' => drupal_get_form("report_details_form"),       
    'this_does_not_matter_too_much1' => array('#markup' => $output,),);

  return $build;
}

Please note that both Form and Table are working, and displayed correctly at the same time when not putting the "if (isset ($_POST['search']))" condition. Also note that the condition is fully working and checked.

Thanks!

  • Where is the Select query? – Dharmender Jun 14 '12 at 5:32
  • It is supposed to be inside the if statement before theming the table. I haven't posted all code in order to keep it simple. – Hugo Jun 14 '12 at 6:28
  • Could you post the complete code..... – Dharmender Jun 14 '12 at 6:37
2

You can use the Table theme. Example :-

$form['data_field'] = array(
'#type' => 'textfield',
'#title' => t('Search!'),
'#id'   => 'search',
'#maxlength' => 1024,
'#description' => t('Search by using tags and free text'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Go!!',
);
...
...
fill $table
...
...
if(sizeof($form_state['input'])!=0) {

$form['table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('Empty Rows')
);
}
return $form.
| improve this answer | |
  • What do you mean? Display my table and my form inside a new table?? Are table not supposed to only be using when displaying tabulated data and not for layout? How would it work? My form is the caption and my table the body of my containing table? I don't really understand what you mean... – Hugo Jun 14 '12 at 7:00
  • What you are trying to do? Do you want that on form submit the table should display your records. and if the form is not submitted then the form is displayed with table having no rows. – Dharmender Jun 14 '12 at 7:06
0

It sounds like it might be related to this post: hook_form being called twice. After the page reloads the form_state is no longer retained. The solution they suggest:

Set $form_state['redirect'] = false to prevent redirection.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.