在drupal中使用“confirm_form()”进行确认动作
时间:2009-07-17 来源:AppleDragon
500)this.width=500;" border="0">
点delete 后
500)this.width=500;" border="0">
We can easily create an action confirm form using confirm_form() function in Drupal. Normally we need this form when user want to delete something and we want user to confirm his/her action. I am showing here an example in which we are listing all the Doctors information with Edit and Delete option. When user click the delete link we will show him the action confirm form with “Delete” and “Cancel” options. If user click the “Delete” button we will delete that Doctor record from database and if user click on “Cancel” we simply show the doctors list again.
Here is the code. I am using the module name “doctor” in this example.
Step 1. First implement hook_menu() to register new path in Drupal.
function doctor_menu() { |
Step 2. Implementing the doctors_list() function to display the list of doctors.
function doctors_list() { |
Step 3. Create a wildcard loader function doctor_user_load() which we used in “doctors/delete/%doctor_user” path. This function checks the given “ID” in path is valid or not. If the given doctor id is not exists in database then “Page not found.” message will display.
function doctor_user_load($doctorid) { |
Step 4. Create the doctor_delete_confirm() function. We are using the “confirm_form()” function in this function to show action confirm form.
function doctor_delete_confirm(&$form_state, $doctor) { |
Step 5. Create the Form API submit function for doctor_delete_confirm form.
function doctor_delete_confirm_submit($form, &$form_state) { |