0

I have 1000 records of users with name and checkbox. I want to show the list of users in table theme. I have use

theme('table', array('header' => $header, 'rows' => $rows));

But how to use it with multistep form. Please find the below code.

function getForm() {
$form = array();
$step1 = array();

drupal_add_js("
function checkUncheckAll(theElement){
  var theForm = theElement.form, z = 0;
  for(z=0; z<theForm.length;z++){
    if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
      theForm[z].checked = theElement.checked;
    }
  }
}", 'inline');

$step1['user'] = array(
   '#type' => 'container',
   '#tree' => TRUE,
   '#prefix' => '<div id="user">',
   '#suffix' => '</div>',
);
$results = db_query("SELECT* FROM {user_token} ut LEFT JOIN {users} u ON u.uid= ut.uid where u.status=1 and u.uid!=0 group by ut.uid ")->fetchAll();

foreach($results as $k=>$result)
{
  $user[$result->uid] = $result->name;
    $defaults = array_keys($user);
}

 $step1['checkall'] = array(
 '#type' => 'checkbox',
 '#title' => t('Select / Unselect all'),
 '#attributes' => array('onclick' => 'checkUncheckAll(this);'),
 '#weight' => -1,
 );

 $step1['user'] = array(
 '#type' => 'checkboxes',
 '#title' => t('Send message to listed users'),
 '#options' => $user,
 //'#default_value' => $defaults,
 '#attributes' => array('class' => array('check_notify_user'))
 );

 $step1['submit']=array(
     '#type'=>'submit',
     '#value'=>t('Next')
 );


$form[] = $step1;

$step2['message'] = array(
  '#type' => 'textarea',
  '#title' => 'Message',
  '#description' => t('No more than 250 words please!'),
  '#wysiwyg' => false,
  '#attributes' => array('maxlength' => 250),
);

$step2['prev'] = array(
  '#type' => 'submit',
  '#value' => t('Previous'),
  '#name' => 'prev',
  '#submit' => array('custom_previous_submit'),
);

$step2['submit']=array(
    '#type'=>'submit',
    '#value'=>t('Submit')
  );

$form[] = $step2;

return $form;

}

0

I assume you know how to do the multi-step form. For the table, you can use Drupal's table theme function. If the table contains only markup, you can do something like this:

$form['table'] = array(
  '#theme' => 'table',
  '#rows' => $rows,    
  '#empty' => 'Empty List - No Entries',
  '#header' => $header,
);

or

$form['table'] = array ('#value' => theme('table', $headers, $rows));

You can use this in multistep form also.

If the table contains actual form elements (such as selects, textfields, etc.), you can wrap them in a form element that calls a theme function, like so:

$form['table'] = array ('#theme' => 'output_table');

$form['table']['element_1'] = array (...);
$form['table']['element_2'] = array (...);

Within 'theme_output_table', generate your $headers and $rows to feed to 'theme_table' by calling 'drupal_render' on the relevant form elements that are children of $form['table'].

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.