我创建了一个可拖动的表格并在其下方添加了一个提交按钮。我可以查看提交按钮,但提交处理程序不起作用。下面是代码。
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 没有被调用。请帮助我。