Prior to working with Drupal, I was able to write php functions that would force a user to confirm before being able to edit/delete any data record they were working with.

I'm trying to do the same within Drupal (version 5), and I found a nice example from Drupal 6 that takes advantage of using a wildcard in the dynamic menu path (http://www.akchauhan.com/create-an-action-confirm-form-using-confirm_for...).

Because you have to address the dynamic path differently in Drupal 5, I'm tripping all over my own feet (http://drupal.org/node/209056).

Does anyone have an example from Drupal 5 similar to the example in the above link? In advance, thanks for helping the "Drubie" (Drupal newbie).

Comments

mpruitt’s picture

I figured out how to do this by reading a lot of posts here on the form. Too many individuals to thank separately, but all of the info I needed was here in the Drupal community.

In the menu hook section:

$items[] = array(
      'path' => 'record/delete',
      'title' => 'You are Deleting a Record!',
      'type' => MENU_CALLBACK,
      'access' => user_access ('delete a record'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('record_delete_confirm'),
    );

The code for the "Delete" link at the end of each table row:

"<a  | href= 'delete/{$data->ID}'>" . t('Delete') . "</a>");

In the above snippent, "{$data->ID}" is included in the path that calls the "record_confirm_delete" function, and can be extracted inside the function by using "func_get_arguments". Since the ID number is the first (and only) value appended to the path, it's in position [0].

There's probably a better way to do this (please let me know if there is), but after capturing the ID value, I "store" it in a hidden field so I can retrieve it inside the follow up function, which in my case is "record_confirm_delete_submit".

function record_delete_confirm(&$form_state){
    $s = func_get_args();
    $record= $s[0]; // this is the record_id value
    
    $form['delete_store'] = array(
		'#type' => 'value',
		'#value' => $record,
	);

    $form['recordid'] = array (
    '#type' => 'hidden',
    '#value' => $record,
    );
    
    return confirm_form($form,
    t('Are you certain you want to delete this record?'),
    isset($_GET['destination']) ? $_GET['destination'] : "record/view",
    t('This action will be irreversible!'),
    t('Delete'),
    t('Cancel'));
}

Once I click the "Delete" button, I get sent to the "record_delete_confirm_submit" function.

I'm an old-school programmer, and I make it a practice to never delete a record from a database, I just mark it as inactive, which is what happens in the following function.

I have another view available only to super admins showing all inactive records. Instead of "Delete", I have "Activate" at the end of each row, so I can re-activate a record if needed.

function record_delete_confirm_submit($form, $form_values) {
//$form_values = $form_state['values'];

    $s = func_get_args();
    $record= $form_values['recordid']; // this is the record_id value

	if ($record) {
        
        $sql = "UPDATE {records} SET RECORD_ACTIVE = 'No' WHERE record_id = $record";
        $rs = db_query($sql);
        
        drupal_set_message('The record has been deleted!');
  	}
        drupal_goto("record/view");
}