0

I just made a $form['table']. It shows enough rows (the count of the total rows in database) only it doesn't show the results. I tried using #value, #title, #markup but nothing works

Screenshot of result:

result

My code:

function push_notifications_stats_form($form, &$form_state) {
$form = array();
$id = $_GET['id'];

$query = db_query('SELECT * FROM push_notifications_messages WHERE msg_appID = :app_id', array(':app_id' => $id));
$qCount = db_query('SELECT * FROM push_notifications_messages WHERE msg_appID = :app_id', array(':app_id' => $id))->rowCount();

$form['table'] = array(
    '#theme' => 'table',
    '#header' => array(t('Message'), t('Device'), t('Date')),
    '#rows' => array(),
    );

foreach($query as $result) {
  for($i = 1; $i <= $qCount; $i++) {
    $form['table']["#rows"]["r$i"] = array(
        "'c1'" => array(
            '#type' => 'textfield',
            '#value' => t('hoi'),
          ),
        'c2' => array(
            '#type' => 'textfield',
            '#title' => t('device')
          ),
        'c3' => array(
            '#type' => 'textfield',
            '#title' => t('device'),
          ),      
      );
  }
}


$form['id'] = array(
'#type' => 'item',
'#title' => 'Application ID',
'#description' => t('The application ID you are viewing: @appId', array('@appId' => $id)),
);  

return $form;

}

When I check the $form with dsm it does show the results.. And also when I use my browsers element inspector it does show the values. Only it puts them inside the first tag. while it should be between the tags

<td #type="textfield" #value="hoi" #data="hoi"></td>
1

1 Answer 1

1

I think you are mis-using #header and #rows properties of the Form API and getting them confused for variables passed to the theme_table function that is being called with the form['#theme'] => 'table'.

This question is similar and might be what you're looking for: How to insert a theme table form inside an existing form?

Perhaps you want to use the tableselect element?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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