Triggers
Archived from the Xataface Users forum.
ozrebel — Wed Jan 03, 2007 10:26 pm
Happy new year to all dataface users.
I just have a quick question on triggers.
Is it possible to include the content of a submitted form in a notification email trigger?
By this I mean if a user submits a record to my database can the trigger that that I have already configured to send me email notification of the inserted record also include the record contents.
Cheers in advance.
Tony
shannah — Thu Jan 04, 2007 12:47 pm
Hi Tony,
YES.
When you implement a trigger, it takes a parameter “$record” that is the record that was changed or inserted. This is a Dataface_Record object, and with it you can get all the information you need.
for example:
- Code: Select all
- `function afterInsert(&$record){
$content = “A record has been added to the {$record->_table->tablename} table\n”;
// Loop through all of the values in the record
// We use strvals() instead of vals() so that non-string
// values are converted to strings.
foreach ($record->strvals() as $key=>$value){
$content .= “$key : $value \n”;
}// Perhaps we want to also include the url to edit this record
// so that when we receive an email, we can just click the link
// to go to the edit form:
$content .= “To edit this record go to “.$record->getURL(‘-action=edit’).”\n”;
// Now we mail this letter to someone – call your mail() function now
…
}`
ozrebel — Thu Jan 04, 2007 5:53 pm
Thanks yet again Steve.
Works like a charm
Of course!!