Creating the Delete Transaction

Creating the Delete Transaction

Finally, the operation which concludes the basic database administration is deleting a record. In order to delete a record you should create, in your site root folder, a new file named "delete.php".

Then open the "index.php" file and add a new column after the "Update" column. In this new column write "Delete" and on this text create a new link pointing to the "delete.php" file. This link has to pass an URL Get parameter that you have to define like for the Update Transaction. The parameter name will be the same: "id_dep". Save the "index.php" file and upload it to the server.

Now open the "delete.php" page. Here, we only need the numeric id to delete a value, so no form is required. But, to further demonstrate the power of first check variable (and also to implement a necessary feature), we will create a deletion confirmation dialog.

To begin, write "Are you sure you want to delete this record?" and go to the next line. Create a form named "deleteForm", using the the POST method and pointing to the "delete.php" page. In this form create an input submit type (button), named "must_delete" and having the label (value) "Yes" and an hidden field named "delete_id" and the "value" field has the following value: "<?php echo $HTTP_GET_VARS["id_dep"]; ?>".

Also, create a second form named "formCancel" must be created containing a submit button named "noDelete" and having a "No" label (value).

Now we have to create the tNG Delete Transaction. Go to "Server Behaviors" tab in the "Application" panel, and press the "plus" button. In the displayed menu, select the "Impakt2->Transactions->Delete Transaction" option.

Similar to the others, we select the Name, the First Check Variable as the name of the submit button in the first form ("must_delete"), the Connection, Table, the Primary Key Column, which is the most important parameter. This instructs the Delete Transaction which is the unique key in the table, given a value of this key, this value represents a single row in the table. We can select the place where it gets the value etc.

In the end, the dialog looks like this:

This page has now a Delete Transaction applied to it.

But when it first reaches this page, the user is first asked if he is sure he wants to delete, because the first check variable is not set, and the transaction is not executed, thus minimizing human error and offering finer grained control over the page flow.

All we need to do now is add a trigger to this page so, when we click on the "Yes" button (confirm delete), the "index.php" page will be loaded.

To create the trigger go to "Server Behaviors" tab in the "Application" panel and choose the "Impakt2->Triggers->Redirect to page" option.

Set Priority to "1", for the option Register to Transaction choose deleteTransaction. Finally for the "Go To" option choose "index.php" and then press the "OK" button.

Save the page, upload entire site to the server and try it in the browser:

Adobe acquired InterAKT
InterAKT has been acquired by Adobe.
Learn more
 
© Adobe Systems Romania. All rights reserved.