0

I managed to get things looking a bit better, However I dont know why the checkbox below is showing like the picture. I want to select the checkbox and make it do something with the corresponding article. By the way I have it, will it work? Thanks in advanceenter image description here.

`function rss_list_form($form, &$form_state) {

$results = db_query("SELECT * FROM {rss_table}");
$i = 0;
foreach($results AS $result) {

    $form[$i] = array(
        '#type' => 'checkbox',
        '#prefix' => '<div style="float:left; margin: 30px;">',
        '#suffix' => '</div>',
    );
    $form[$result->GUID] = array(
        '#type' => 'item',
        '#title' => $result->title,
        '#markup' => $result->description,
        '#prefix' => '<div style="float:clear; background: #e0e2e6; border: 4px solid #c5c9cf; padding: 15px; width: auto; margin-left: 80px;">',
        '#suffix' => '</div>',
    );
    $i++;
}
$form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
);

return $form;

}`

4
  • As you are using Drupal 7, and need checkboxes in the table which will be wrapped in Form then you should use theme_tableselect. In this link you will find examples to how to use this theme. Jul 13, 2014 at 18:18
  • Thanks, I will look into that. I will post my progress later!
    – M1ndr1ft
    Jul 13, 2014 at 18:25
  • I am a bit confused, my header would be the Select(checkbox) and Article which includes the 2 table fields in an item. How would I code the $rows[]? is it possible?
    – M1ndr1ft
    Jul 13, 2014 at 18:37
  • Have a look at the link jaypan.com/tutorial/…. This will help you in developing this. Jul 13, 2014 at 18:43

2 Answers 2

1

I manage to get things working like I wanted !! So I will include a screenshot and the code for people on the same boat. enter image description here

function rss_list_form($form, $form_state) {

$header = array(
'article' => t('Article'),
);

$rows = array();
$sql = "SELECT * FROM {rss_table}";
$result = db_query($sql);
    foreach ($result as $dbrow) {
    $rows[$dbrow->GUID] = array(
        'article' =>
        '<h3>'.$dbrow->title .'</h3>'.'<br>'
        .'<p>'.$dbrow->description.'<p>'.'<br>'
        .$dbrow->date .'<br>'.'<em>'.$dbrow->link.'</em>'.'<br>',
    );
    }
$form['rss_select'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $rows,
    '#empty' => t('No articles found.'),
);
$form['import'] = array(
    '#type' => 'button',
    '#value' => t('Import'),
    '#weight' => 0,
);
$form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
);
$form['delete'] = array(
    '#type' => 'button',
    '#value' => t('Delete'),
);
return $form;

}

-1

Do it without the table first. Just the form with the form elements. Once you get that right and it works you then have to create a new theme function for it:

  • implement hook_theme and define a theme function for the form
  • set form['#theme'] in the original form to that of your new theme function
  • implement the new theme function. Here you need to load all of your form elements into structures as required by theme_table, and call theme_table on it. And then call drupal_render_children on the form so as to render the rest of the form (hidden elements etc that are required by Drupal FAPI).
1
  • There is no need of another theme function, since Drupal has one that can be used in this case.
    – apaderno
    Jul 14, 2014 at 7:01

Your Answer

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

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