How do I add an edit button on each row of a "tableselect" form element?

The code I have is the following one.

function example_elements_form() {
    $form = array();
    $header = array(
        'title' => array('field' => 'n.title', 'data' => t('Title')),
        'author' => array('field' => 'u.name', 'data' => t('Author')),
    $query = "SELECT n.nid, n.title, u.name FROM {node} n INNER JOIN {users} u ON n.uid = u.uid". tablesort_sql($header);
    $result = pager_query(db_rewrite_sql($query));
    while($partial_node = db_fetch_object($result)) {
        $options[$partial_node->nid] = array(
            'title' => check_plain($partial_node->title),
            'author' => theme('username', $partial_node),
    if (!empty($options)) {
        $form['nodes'] = array(
            '#type' => 'tableselect',
            '#header' => $header,
            '#options' => $options,
        $form['pager'] = array('#value' => theme('pager'));
        $form['submit'] = array(
            '#type' => 'submit',
            '#value' => t('Submit'),
    return $form;

1 Answer 1


Check out http://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/node_admin_nodes/7

In particular, take a look at the lines that contain "operations". You need to set up a new element in $header to contain a column for the "operations", and then add at least one operation inside $options for each row.

You could either manually add a link to the edit with l(), or you could use module_invoke('node_operations') - again, an example of that is shown in the API.

  • Can I use image button instead of using text button for Edit button i.e, i want image instead of "EDIT"
    – Dharmender
    Commented May 23, 2012 at 9:29
  • Sure. You can use the l() function to add a class to your "a" tag, and then you can use CSS to put a background image on it and hide the text. Commented May 23, 2012 at 9:54

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.