2

I have a table named "Table1" in my Drupal, where I added fields by getting the inputs via form. The form is created by custom module. My next requirement was to again create another form, but this time I want to show the user by means of a Table format, the previously collected data in the form page itself. But I got stuck in this part.

The idea is: I want to bring the contents of "Table1" having attributes "empid" and "empname" in the right side of Form Page, so that the user can check the contents and enter current input accordingly. How is it possible?

1 Answer 1

1

Yes you can do this. First of all you need to fetch the 'Table1' data in top of the form.

$query = db_select('Table1' , 'tb');
    $query->fields('tb');
    $results = $query->execute()->fetchAll();

//table structure

$Details = '<table><tr><td style="width:15%;"></td><td style="width:30%;">Employee Id</td><td style="width:10%;">Employee Name</td></tr>';
    foreach($results as $res)
    {
        $Details .= '<td>'.$res->empid.'</td>';
        $Details .= '<td>$'.$res->empname.'</td>';  
    }

$form['details'] = array(
        '#type' => 'item',
        '#markup' => $Details,
        '#suffix' => '</div>'
    );

$form['eid'] = array(
    '#type' => 'textfield' ,
    '#title' => t('Employee Id'),
    '#maxlength' => 45,
    '#required'=> true,
);
$form['ename'] = array(
    '#type' => 'textfield' ,
    '#title' => t('Employee Name'),
    '#maxlength' => 45,
    '#required'=> true,
);  


 $form['submit'] = array(
        '#type' => 'submit' ,
        '#value' => 'Submit'
    );  
1
  • Thanks @Smalution. Find out the way to position it. But i couldnt get the way to configure each rows seperatley. Can u help
    – Syamili V
    Commented Nov 3, 2014 at 6:39

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.