tablename_after_insert()
Called after executing the insert query (but before executing the ownership insert query). If you open the generated hooks/tablename.php file in a text editor (where tablename is the name of the concerned table), you can see this function defined as follows:
1
2
3
4
function tablename_after_insert($data, $memberInfo, &$args){
return true;
}
Parameters:
$data is an associative array where the keys are field names and the values are the field data values that were inserted into the new record. It also includes the item $data['selectedID'] which stores the value of the primary key for the new record.
$memberInfo is an array containing details of the member who signed in. Please refer to memberInfo for more details.
$args is currently not used but is reserved for future uses.
Return value:
A boolean true to perform the ownership insert operation or false to cancel it. Warning: if a false is returned, the new record will have no ownership info.
Example:
The following example sends a notification email to an employee when a user submits a new record. The email contains the record data.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function tablename_after_insert($data, $memberInfo, &$args){
// to compose a message containing the submitted data,
// we need to iterate through the $data array
foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}
sendmail(array(
'to' => '
[email protected]',
'name' => 'Recipient Name',
'subject' => 'A new record needs your attention',
'message' => "The following new record was submitted by {$memberInfo['username']}: \n\n" . $messageData
));
return true;
}