سؤال

I am working on Drupal 7. I want to display a form on "Error! The website encountered an unexpected error. Please try again later." page. I have copied the maintenance-page.tpl.php file to my theme folder. 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.

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. and place $form['submit'] to $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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top