The tabs should not use the form api to be rendered,

it breaks any form you are trying to add inside tabs, and you cannot commit the forms at all.

HTML does not allows forms into forms.

It should be a generating function proper to tabs instead of using the form api of drupal.

Comments

nedjo’s picture

Category: feature » support
Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)

Tabs do not generate a <form> element.

Can you post the code you're working with?

Sylvain Lecoy’s picture

This is the code:

<?php
function module_app(&$form_state, $a1, $a2, $a3) {
  $form = array();
  
  $form['app'] = array(
    '#type' => 'tabset',
  );
  
  // Review tab
  $review = views_get_view('review');
  $review->set_display('default');
  $review->set_arguments(array(0 => $a1));
  
  $review->pre_execute();
  $review->execute();
  
  $form['app']['review'] = array(
    '#type'     => 'tabpage',
    '#title'    => t('Review'),
    
    '#content'  => $review->render(),
    
    // Default tab at startup.
    '#selected' => TRUE,
  );
  
  if (isset($review->result[0])) {
    $nid = $review->result[0]->nid;
    $comment_count = $review->result[0]->node_comment_statistics_comment_count;
  }
  else {
    $comment_count = 0;
  }
  
  $review->post_execute();
   
  // Replies tab 
  $reply = views_get_view('read_replies');
  $reply->set_display('default');
  $reply->set_arguments(array(0 => $nid));  
  $reply->pre_execute();
  $reply->execute();
  
  
  $form['app']['replies'] = array(
    '#type'     => 'tabpage',
    '#title'    => t('Replies') . " <span class='counter'>$comment_count</span>",
  
    '#content'  => $reply->render(),
  );
  
  $form['app']['add_review'] = array(
    '#type'     => 'tabpage',
    '#title'    => '+',
  
    '#content'  => '+',
  );
  
  return $form;
}
?>

And this is where I am calling the function:

<?php
  $items['app/%/%/%'] = array(
    'page callback'   => 'drupal_get_form',
    'page arguments'  => array('module_app', 1, 2, 3),
    'access callback' => TRUE,
    'file'            => 'module.inc',
    'type'            => MENU_CALLBACK,
  );
?>
Sylvain Lecoy’s picture

Sorry duplication.

nedjo’s picture

Status: Postponed (maintainer needs more info) » Active

It's outputting a form because you're calling this through drupal_get_form(). If you don't want a form, use 'module_app' as the menu item callback.

nedjo’s picture

And change the last line of the function to


  // Render the tabset.
  return drupal_render($form);

(Though you'll probably want to change the variable name to e.g. $tabset.)

Sylvain Lecoy’s picture

Thank you for this tip.

It was effectively the calling of drupal_get_form which added the form element (surely in the theme function).

I suggest you to update the tabsexample.module as well, this was confusing how to render tabs.

<?php
$items['tabsexample'] = array(
    'title' => 'Tabs example, basic',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tabsexample_form'),
    'access arguments' => array('access content'),
    'type' => MENU_NORMAL_ITEM,
  );
?>