在自定义模块中未正确调用Drupal Submit处理程序

时间:2014-10-23 07:41:54

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

我有这个代码用于调用表单而不是提交它..

<?php 
// hook_menu
function pricepackages_menu()
{
    $items = array();
    $items['membership/packages'] = array(
        'title' => t('Manage Membership Packages'),
        'page callback' => 'drupal_get_form',
        'page arguments' => array('pricepackages_form'),
       //'access callback' => TRUE,
       'access arguments' => array('access administration pages'),
    );
    return $items;
}
// FORM SHOW HOOK
function pricepackages_form($form, &$form_state)
{
    $form = array();

    $form['packagename'] = array(
        '#type' => 'textfield',
        '#title' => 'Package Name',
        //'attribute' => array('class' => 'package'),
        '#required' => TRUE,
    );
    $form['packageDescp'] = array(
        '#type' => 'textfield',
        '#title' => 'Package Short Description',
        //'attribute' => array('class' => 'package'),
        '#required' => FALSE,
    );
    $form['price'] = array(
        '#type' => 'textfield',
        '#title' => 'Package Price',
        //'attribute' => array('class' => 'package'),
        '#required' => TRUE,
    );
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Submit'),
    );
    $form['submit'][] = array('package_get_form'=> array());

    return $form;
}

function package_get_form($form, &$form_state)
{
    drupal_set_message('working');
?>
    <script language="javascript">
        alert("aaa");
    </script>
<?php
return; 
    }
?>

但是这个没有按比例进行,并且没有在特定表格上提交表格...... 既不显示警报也不显示消息......

请帮帮我......

1 个答案:

答案 0 :(得分:1)

这部分不正确:

$form['submit'][] = array('package_get_form'=> array());

要添加提交回调,只需写下:

$form['submit'][] = 'package_get_form';

您甚至不需要这一行,因为表单API提供了一个默认的回调,将“_submit”附加到表单id / callback。对于你的情况:

pricepackages_form_submit()