Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip validation on node delete in Drupal 7

How can I accomplish skipping validation when the user attempts to delete a node in Drupal 7? I am calling my custom validation function in the following manner:

function my_issue_form_alter(&$form, &$form_state, $form_id) {
    switch ($form_id) {
        case 'my_issue_node_form':{
            $form['#validate'][] = 'my_issue_node_form_validate';
            break;
        }
    }
}

function my_issue_node_form_validate($form, &$form_state) {
    //custom validation done here
}

I've been looking around for a couple days now and most of the possible solutions are considering the developer is creating a custom form, which I am not.

Thanks in advance for any tips/advice.

like image 602
MTsrb Avatar asked Aug 02 '13 15:08

MTsrb


2 Answers

Great question, this has bugged me for years and I hadn't even realised it. Something like this ought to do it:

function my_issue_form_my_issue_node_form_alter(&$form, &$form_state, $form_id) {
  // Make sure it's an edit form.
  if (!empty($form['nid']['#value'])) {
    // The nid is required for the delete confirmation form.
    $form['actions']['delete']['#limit_validation_errors'] = array(array('nid'));
  }

  $form['#validate'][] = 'my_issue_node_form_validate';
}
like image 192
Clive Avatar answered Oct 01 '22 11:10

Clive


I think the key point here is node. Check out hook_node_validate() if I were you I would see the stack and find it out.

let me know when u have an update.

like image 40
Vishal Khialani Avatar answered Oct 01 '22 12:10

Vishal Khialani