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 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
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
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.