I'm developing a custom module for Drupal 6, that creates a simple form. My problem is that the submit function is not being called/processed!!! Here's my code:
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_settion开发者_StackOverflowgs_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!!!');
}
Now, the form rendering & the data retrival of the Db is just perfect. It's when I click the submit button, I get nothing at all!! Only the page refreshes & the messages doesn't appear!!
Any idea why?!!!!
use
return $form;
instead of
return system_settings_form($form);
and also
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!!!');
}
the problem was if you use system_setting_form then it start behaving as a system setting page that is generally used to store some information in database. So making it normal form you need to return only $form.
Include a submit handler and then assign it a function
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#submit' => array('my_module_function_submit'),
);
my_module_function_submit($form, $form_state){
.
.
.
.
.
}
Refer this link https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit_property
精彩评论