提交按钮不在主题功能中工作

时间:2013-03-16 20:09:58

标签: drupal-7 form-submit form-api

我创建了一个可拖动的表,并在其下面添加了一个提交按钮。我能够查看提交按钮,但提交处理程序不起作用。以下是代码。

function form_content_reorder($form, &$form_state)
{    
$form = array();
$form['items'] = array();
$form['items']['#tree'] = TRUE;
$form['#theme'] = 'usercontentranking_reorder_form'; 
$form['name'] = array(
 '#type' => 'item',
 '#markup' => 'Hello  '.get_genderval($user_data['gender']).$user_data['user_name'],);
$form['submit'] = array(
 '#type' => 'submit',
 '#value' => t('Save Preferences'),
 '#submit' => array('user_content_ranking_save'),);
 return $form;
 }

function usercontentranking_theme($existing, $type, $theme, $path) {
$themes = array(
'usercontentranking_reorder_form' => array(
  'render element' => 'element'
),
);
return $themes;
}

function theme_usercontentranking_reorder_form($vars) {
$element = $vars['element'];
drupal_add_tabledrag('draggable_table', 'order', 'sibling', 'weight-group');
$header = array(
 'label' => t(''), 
 'label2' => t(''),
 'weight' => t('Weight'),
 'operations' => t('Operations'),
); 
$rows = array();

foreach (element_children($element['items']) as $key) {
$row = array();
$row['data'] = array();
$row['data'][] = drupal_render($element['items'][$key]['title']);
$row['data'][] = drupal_render($element['items'][$key]['user_fields']);
$row['data'][] = drupal_render($element['items'][$key]['weight']);
$row['data'][] = drupal_render($element['items'][$key]['operation']);
$row['class'] = array('draggable');
$rows[] = $row;

$themes = drupal_render($element['name']);

$themes .=theme('table', array(
  'header' => $header, 
  'rows' => $rows,
  'attributes' => array('id' => 'draggable_table'),
));

$themes .= drupal_render($element['submit']);

return $themes;
}

function user_content_ranking_save($form, &$form_state)
{
  print "text";
}

这条线   $ themes。= drupal_render($ element ['submit']); 能够显示按钮但是没有调用函数user_content_ranking_save。 请帮助我。

1 个答案:

答案 0 :(得分:0)

添加以下三行:

$themes .= drupal_render($element['form_id']); 
$themes .= drupal_render($element['form_build_id']);
$themes .= drupal_render($element['form_token']);

之前:

$themes .= drupal_render($element['submit']); 

解决了这个问题。