0

I used hook_form_alter to add a required 'confirmation' checkbox to the node deletion form and the #required status is not honored.

The fields/fieldset are property displayed 'node-delete-confirmation' form.

Here is the hook_form_alter content:

$form['warning'] = array(
    '#type' => 'fieldset',
    '#title' => t('Warning! - You Must Check The Box Below To Continue'),
    '#weight' => -30,
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
);
$form['confirm_delete'] = array(
    '#title' => t('I fully understand that this action cannot be undone and that statistics linked to this item will be permanently removed.'),
    '#type' => 'checkbox',
    '#required' => TRUE,
    '#default_value' => 0,
);

How can I enforce the 'required' status so that nodes cannot be deleted until the confirmation is acknowledged.

If I change the code, to completely remove the added fieldset everything works as it should.

Works:

$form['warning']['confirm_delete'] = array(
'#title' => t('I fully understand that this action cannot be undone and that statistics linked to this item will be permanently removed.'),
'#type' => 'checkbox',
'#required' => TRUE,
'#default_value' => 0,

);

  • Seems to work if I completely remove the fieldset. I would still prefer the fieldset as it looks way better. – Citricguy Jul 2 '11 at 2:48
3

You can add your form validation handler (hook_form_alter):

$form['#validate'] = array('delete_validation_handler') + $form['#validate'];

Your validation handler:

function delete_validation_handler($form, $form_state){
    if(!$form_state['values']['confirm_delete'])
        form_set_error('confirm_delete', t('Message about to confirm it first'))
}
2

Try this one: http://drupaldeveloper.in/codelet/drupal-make-single-checkbox-required-field It will always work! Please note, its for Drupal 6.x, but you can use it for 7.x as well!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.