【问题标题】:Add form Drupal Error Page添加表单 Drupal 错误页面
【发布时间】:2014-05-09 09:24:37
【问题描述】:

我正在开发 Drupal 7。我想在“错误!网站遇到意外错误。请稍后再试”上显示一个表单。页。 我已将 maintenance-page.tpl.php 文件复制到我的主题文件夹中。并在该模板中呈现了一个表单。到目前为止,表单正在显示,但是当我提交表单时,drupal 没有进入 _validate 和 _submit 函数。

这里是代码 模板文件

<div class="complaint-form-message">
                <h5>
                    We’re sorry you’re having trouble with myCCS! 
                    Tell us about the error you’ve experienced and we’ll 
                    get right back to you!
                </h5>
            </div>
            <div class="complaint-form">
                <?php echo drupal_render(drupal_get_form('complaint_form_form')); ?>
            </div>

表单函数

function complaint_form_form($form, &$form_state){
$form['name'] = array(
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => 'First Name & Last Name',
);

$form['email'] = array(
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => 'Email Address',
);

$form['browser'] = array(
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => 'What browser you are using?',
);

$form['tell_us_about_error'] = array(
    '#type' => 'textarea',
    '#required' => TRUE,
    '#title' => 'Tell us about error you experienced?',
);

$form['attachment'] = array(
    '#type' => 'file',
    '#title' => 'Attachment',
);

$form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#submit' => 'complaint_form_submit',
);


return $form;

}

function complaint_form_validate($form, $form_state){
  echo 'PPPPP<pre>'; print_r($form_state); die;
  $mail = $form_state['values']['submitted_tree']['email'];
  if (!valid_email_address($mail)) 
    form_set_error('[submitted][email_address]', t('The email
    address appears to be invalid.'));
}

function complaint_form_submit($form, $form_state){
  echo 'DDDDD<pre>'; print_r($form_state); die;
  $values = $form_state['values'];

}

【问题讨论】:

    标签: drupal-7


    【解决方案1】:

    你的#submit 是一个数组,你已经把它作为字符串, 因此,将您的提交条目更改为以下内容。 并将 $form['submit'] 放到 $form['actions']['submit'];

    $form['actions']['submit']=array(
        '#type' => 'submit',
        '#value' => t('Submit'),
        '#submit' => array('complaint_form_submit'),
    );
    Note: **'#submit' is an array**
    

    添加验证

    $form['#validate'][] = 'complaint_form_validate';
    

    注意:'#validate' 是一个数组

    【讨论】:

    • 感谢您的回复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-11
    相关资源
    最近更新 更多