I want to create receive item from my purchase order node. I have to create a table and displayed all data from node. In last column of table I need to add a textfield and a submit button under the table.

enter image description here

I have read a lot of reference, but still getting error. I hope somebody help to solve my problem.

by this code i want to create a form in table

function wespi_po_page(){
    $nid =arg(1);
    $form = array();
    $items = db_query('Select
                          Count(field_data_field_item.delta) As items
                          node Inner Join
                          field_data_field_item On node.nid = field_data_field_item.entity_id
                          node.nid = :nid',array(':nid'=>$nid)
    drupal_set_message('Items counted : ' . $items);

$header = array(
    array('data' => 'Title', 'field' => 'title'),
    array('data' => 'On order', 'field' => 'on_order'),
    array('data' => 'On received', 'field' => 'on_received'),
    array('data' => 'Receive', 'field' => 'receive'),

    $result = db_query ('
                          field_data_field_item.field_item_nid As nid,
                          node.title As title,
                          field_data_field_on_order.field_on_order_value As on_order,
                          field_data_field_on_received.field_on_received_value As on_received
                          field_data_field_item Left Join
                          field_data_field_on_received On field_data_field_item.entity_id =
                            field_data_field_on_received.entity_id And field_data_field_item.delta =
                            field_data_field_on_received.delta Left Join
                          field_data_field_on_order On field_data_field_item.entity_id =
                            field_data_field_on_order.entity_id And field_data_field_item.delta =
                            field_data_field_on_order.delta Inner Join
                          node On field_data_field_item.field_item_nid = node.nid
                          field_data_field_item.entity_id = :nid
                        Group By
                          field_data_field_item.field_item_nid', array(':nid' => $nid)
    $rows = array();   
    foreach ($result as $data) {
        $rows[] = array(
                    'data' => array(
                          l($data->title, 'node/'. $data->nid),
    $output = theme('table',
                                'header' => $header,
                                'sticky' => TRUE,
    return $output;

function wespi_po_theme($existing, $type, $theme, $path) {
  return array(
    'wespi_po_table' => array(
      'render element' => 'element'

function wespi_po_tab_page_form_submit(){
    drupal_set_message($items . ' Items received');
  • What is the error you are getting? Jan 27, 2015 at 17:23

4 Answers 4


implements hook_form in your module and fetch any data you want from database as well as add textfield. After completion of all form items you can theme it as using

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

in your page callback function. for more information you can check form api in drupal.org.


I'm not completely sure, but I know you might could check how the https://drupal.org/project/diff module does this when viewing the node/%nid/revisions

It adds a compare button revisions button to the table.

Hope that helps


You can use below link for meeting above Drupal 7 Forms Table

It basically covers theme table & passing form as reference.


You can use Views to display the items corresponding to your node. You may use contextual filter to get the node id from the URL.

Once you have the view appearing in the page, follow the steps provided in this article to create a form and submit data.


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.