Drupal 7形成状态未定义的索引

时间:2013-05-23 05:43:18

标签: drupal

我在.module文件中创建了这样的表单:

function form_registration_form($form, &$form_state) {
$form['registration']['email'] = array(
'#title' => t('EMAIL ADDRESS'),
'#type' => 'textfield',
    '#required' => TRUE,
    '#size' => 44,
    '#maxlength' => '80',
    '#rules' => array(
        'email', 
        'length[10, 50]',
    )
  );
  $form['registration']['password'] = array(
    '#title' => t('PASSWORD'),
    '#type' => 'password',
    '#required' => TRUE,
    '#size' => 44,
    '#maxlength' => '80',
  );
  $form['registration']['submit'] = array(
    '#value' => 'SIGN IN',
    '#type' => 'submit',
    '#submit' => array('form_registration_handler')
    );
  return $form;
}
function form_registration_handler($form, &$form_state){
    $email = $form_state['registration']['email'];
        drupal_set_message($email);
}

然而drupal总是说“未定义的索引:在form_registration_form_submit()中注册”。我真的不知道我在这里做错了什么。任何建议对我都非常有用。非常感谢你。

2 个答案:

答案 0 :(得分:1)

您始终可以启用Devel模块和dsm($ form)提交功能。例如:

function form_registration_handler($form, &$form_state){
    dsm($form);
    dsm($form_state);
}

通过DSMing,您可以轻松找到要在提交功能中使用的值。

答案 1 :(得分:0)

将此行添加到form_registration_form函数的头部:

$form = array();
$form['registration'] = array();

通知显示为$ form ['registration']未声明为void数组。