HOW TO write my own trigger on adding/updating operations?

Talk and info about common issues

Moderator: alexandrleonenko

administrator
Site Admin
Site Admin
Posts: 6009
Joined: Jan 7th, '09, 23:18
Contact:

HOW TO write my own trigger on adding/updating operations?

Postby administrator » Jul 31st, '12, 20:57

Sometimes we need to make additional database/code operations before or after adding/updating records.
How can we do it? It's very simply!

1st way.
-------
You can always rewrite AddRow() and UpdateRow() methods in DataForm class to suit your needs.

2nd way.
--------
First of all you need to receive mode and record ID:
Remember you need to use prefix_ of your DataForm, defined in $unique_prefix = "prefix_";

Code: Select all

$mode = (isset($_REQUEST['prefix_mode'])) ? $_REQUEST['prefix_mode'] : "";
$rid = (isset($_REQUEST['prefix_rid'])) ? $_REQUEST['prefix_rid'] : "";

Ex.: (for prefix "abc_")

Code: Select all

$mode = (isset($_REQUEST['abc_mode'])) ? $_REQUEST['abc_mode'] : "";
$rid = (isset($_REQUEST['abc_rid'])) ? $_REQUEST['abc_rid'] : "";

Example for such operations:

// Perform your own operation here

Code: Select all

if($mode == "add"){           
      .. you code here....
      .. example:  mysql_query("SELECT * FROM table WHERE id=".intval($rid));
}


Code: Select all

if($mode == "update" && $rid == "-1"){           
      .. you code here....
}


NOTE:
If you want to run these operations "before" running the DataForm, you must write them before $dform->Bind(); or after - if you want to run them "after" running the DataForm component.

asawyer13
Senior
Senior
Posts: 32
Joined: Jul 19th, '11, 11:26

Re: HOW TO write my own trigger on adding/updating operations?

Postby asawyer13 » Feb 9th, '14, 17:49

My prefix is 'aas_', Can you clarify exactly what needs to be in the ISSET code?

Is it
$mode = (isset($_REQUEST['aasmode'])) ? $_REQUEST['aasmode'] : "";
$rid = (isset($_REQUEST['aasrid'])) ? $_REQUEST['aasrid'] : "";

or something else?

and I put this plus my sql update code AFTER the databind if I want to do it after the data has been updated?

Thanks

administrator
Site Admin
Site Admin
Posts: 6009
Joined: Jan 7th, '09, 23:18
Contact:

Re: HOW TO write my own trigger on adding/updating operations?

Postby administrator » Feb 10th, '14, 06:58

It must be

$mode = (isset($_REQUEST['aas_mode'])) ? $_REQUEST['aas_mode'] : "";
$rid = (isset($_REQUEST['aas_rid'])) ? $_REQUEST['aas_rid'] : "";


Return to “ApPHP DataForm {HOW TO}”