Create custom triggers

There are two custom triggers that are registered to the Custom Transaction presented in the previous section: TriggerBEFORE_AddField1 and TriggerEND_Redirect1. The other two triggers are standard ones, present for the regular Insert Transaction A transaction is a group of SQL statements whose effects are logically connected. Anything from simple queries to inserting, and deleting operations can be considered a transaction, as well as more complex groups of several statements which accomplish a specific task. section.

If you compare the SQL statement's columns and the columns added by addColumn() method, you'll notice that {Forename} is only present in the SQL statement. This means that the Custom Transaction will not know how to evaluate the {Forename} placeholder at runtime. The solution is to use the TriggerBEFORE_AddField1 to add the Forename field to the transaction:

//trigger A trigger is a SQL procedure that performs an action when a transaction (INSERT, UPDATE, DELETE) occurs. You can use triggers to perform validation of input data, to automatically generate a value for a newly inserted row, to read from other tables for cross-referencing purposes, or to support alerts through e-mail messages. AddField1
function TriggerBEFORE_AddField1(&$tNG) {
$tNG->addColumn("Forename", "STRING_TYPE", "EXPRESSION", "{Surname} used as Forename");
return null;

}

 

The only method type allowed when using addColumn() after the transaction has started is “VALUE”. Also, please notice the use of an expression to set the value of Forename.
The other custom trigger used in this Custom Transaction is an END custom redirect The redirect server behavior A server behavior is a reusable component for server-side development. They add blocks of code to your pages for accomplishing specific tasks. Dreamweaver comes with several default server behaviors and the InterAKT extensions add many more to this list. loads a new site page after a transaction is executed. For instance, users could be automatically redirected to their inbox after they log in to the website. trigger:

function TriggerEND_Redirect1(&$tNG) {
$redObj = new tNG_Redirect($tNG);
$redObj->setURL("insert.php?UserID={UserID}&Forename={Forename}&Email={Email}");
$redObj->setKeepURLParams(true);
return $redObj->Redirect();
}

 

The actual redirect is done using an instance of the tNG_Redirect object. Also notice the use of setURL(..) method that (like evaluateFieldExpr(..)) can replace the placeholders used in the passed parameter string with their actual values.

Related Topics