[英]Add form Drupal Error Page
I am working on Drupal 7. I want to display a form on "Error! The website encountered an unexpected error. Please try again later." 我正在使用Drupal7。我想在“错误!该网站遇到意外错误。请稍后再试”上显示一个表格。 page.
页。 I have copied the maintenance-page.tpl.php file to my theme folder.
我已将maintenance-page.tpl.php文件复制到主题文件夹中。 and rendered a form in that template.
并在该模板中呈现一个表单。 Up until now the form is showing but when I submit the form, drupal is not getting into _validate and _submit functions.
到目前为止,该表单一直显示,但是当我提交表单时,drupal尚未进入_validate和_submit函数。
Here is the code Template File 这是代码模板文件
<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>
Form Function 表格功能
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'];
}
Your #submit is an array you have put is as string, So change your submit entry to the following. 您的#submit是作为字符串放置的数组,因此将您的Submit条目更改为以下内容。 and place $form['submit'] to $form['actions']['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**
to add validations 添加验证
$form['#validate'][] = 'complaint_form_validate';
Note: '#validate' is an array 注意: “#validate”是一个数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.