我正在为Drupal 6开发一个自定义模块,它创建了一个简单的表单。我的问题是提交函数没有被调用/处理!这是我的代码:
function listgroups_menu(){
$items['user/%/groups-settings'] = array(
'title' => 'Groups Settings',
'page callback' => 'listgroups_groups_list',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function listgroups_groups_list ($uid){
/*
* Couple lines here to access the DB & get the user's $groups.
*/
variable_set('listgroups_database_result', $groups );
$output = drupal_get_form('listgroups_settiongs_form');
return $output;
}
/**
* Form Builder
*/
function listgroups_settiongs_form(){
$groups = variable_get('database_result', array());
//Building the form
$form['display_option'] = array(
'#type' => 'checkbox',
'#title' => t('Show my group.'),
);
$form['groups_selection'] = array(
'#type' => 'radios',
'#title' => 'Please select your group',
'#options' => $groups,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return system_settings_form($form);
}
/**
* Submition
*/
function listgroups_settiongs_form_submit($form, &$form_state){
echo "<pre>I'm heeeeeeeeeeeeeeeeeeeeeerr!!!</pre>";
drupal_set_message('Your settings have been saved! YES!!!');
}
现在,表格渲染&amp; Db的数据回顾是完美的。当我点击提交按钮时,我什么都没得到!只有页面刷新&amp;消息没有出现!!
知道为什么吗?!!!!
答案 0 :(得分:1)
使用
return $form;
而不是
return system_settings_form($form);
以及
function xyz_form_submit($form, &$form_state){
//echo "<pre>I'm heeeeeeeeeeeeeeeeeeeeeerr!!!</pre>";
drupal_set_message('<pre>I\'m heeeeeeeeeeeeeeeeeeeeeerr!!!</pre>Your settings have been saved! YES!!!');
}
问题是如果你使用system_setting_form然后它开始表现为系统设置页面,通常用于在数据库中存储一些信息。因此,使其成为正常形式,您只需要返回$ form。
答案 1 :(得分:0)
包含提交处理程序,然后为其分配一个函数
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#submit' => array('my_module_function_submit'),
);
my_module_function_submit($form, $form_state){
.
.
.
.
.
}
请参阅此链接https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit_property