0

I have tabular format data and each row I have an edit and delete links , on clicking on the delete link it should ask for a confirmation to delete and if press delete only I need to delete. Now its asking for confirmation but not deleting any. Instead its giving me a blank page. Is it because it's submitted to the same function? It's not going to the products_delete_confirm_submit() on submission by the way. Or is there any workaround for this?

Here is the try :

Menu call back:

 function mailusers_menu() {
     $items['mailusers/usergroup/delete'] = array(
        'title' => 'Delete User group',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('products_delete_confirm', 3),
        'type' => MENU_CALLBACK,
        'access callback' => TRUE,
        'access arguments' => array('access admin tab'),
      );
 return $items;
}

callback function

function products_delete_confirm($form,$product_code) {
$form['_product'] = array(
        '#type' => 'value',
        '#value' => $product_code,);
//$form['#action'] = url("mailusers/products_delete_confirm_submit");
//      //drupal_set_message($product_code);

return confirm_form($form,t('Are you sure you want to delete '.$product_code.' Product?'),
        isset($_GET['destination']) ? $_GET['destination'] : "mailusers",t('This action cannot be undone.'),t('Delete'),t('Cancel'));

}

Delete submit handler:

function products_delete_confirm_submit($form, &$form_state) { 
  $form_values = $form_state['values'];
  if ($form_state['values']['confirm']) {
  $param = $form_state['values']['_product'];
    drupal_set_message(t('Product ' .$param.' will get deleted.'));                             
    db_query('DELETE FROM {content_type_usergroup} WHERE vid = %d', $param);
    drupal_set_message(t('usergroup has been deleted.'));          
    drupal_goto('mailusers');
 }
}

And in the table I am calling the delete link href="mailusers/usergroup/delete/10"

1 Answer 1

1

Don't bother testing the value of confirm, the user is only given a choice to submit or go back (with cancel link).

function products_delete_confirm_submit($form, &$form_state) { 
  $param = $form_state['values']['_product'];
  drupal_set_message(t('Product ' .$param.' will get deleted.'));                             
  db_query('DELETE FROM {content_type_usergroup} WHERE vid = %d', $param);
  drupal_set_message(t('usergroup has been deleted.'));          
  $form_state['redirect'] = 'mailusers';
}

Also, your access callback is set to TRUE, which bypass all permission checking.

Final answer

It should be products_delete_confirm(&$form_state, $product_code), see the example at https://www.drupal.org/node/751826#creating, you were messing with your form structure.

5
  • But what will have in $form_state['values']['confirm'] then ?
    – KTM
    Commented Aug 3, 2015 at 14:48
  • You should still have the value 1, indeed. If your submit is still not called, post the whole code, including potential form_alters
    – SebCorbin
    Commented Aug 3, 2015 at 15:11
  • i removed the access callback and then its submitting though i cant give function products_delete_confirm($form,$product_code) like this when giving $form it gives me Cannot use string offset as an array error
    – KTM
    Commented Aug 3, 2015 at 15:37
  • 1
    It should be products_delete_confirm($form_state, $product_code)
    – SebCorbin
    Commented Aug 3, 2015 at 15:50
  • this was the cause of getting the blank page , when i checked the error log !
    – KTM
    Commented Aug 3, 2015 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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