我的表单提交功能不起作用

发布于 2024-12-09 19:02:00 字数 1585 浏览 0 评论 0原文

我正在为 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!!!');
 }

现在,表单渲染&数据库的数据检索非常完美。当我点击提交按钮时,我什么也没得到!仅页面刷新&消息没有出现!!

知道为什么吗?

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_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!!!');
 }

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?!!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乖不如嘢 2024-12-16 19:02:00

使用

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 即可。

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.

夜深人未静 2024-12-16 19:02:00

包含提交处理程序,然后为其分配一个函数

 $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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文