Triggers

A place for users and developers of the Xataface to discuss and receive support.

Postby 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
ozrebel
 
Posts: 18
Joined: Wed Dec 31, 1969 5:00 pm

Postby 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
    ...
}
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby ozrebel » Thu Jan 04, 2007 5:53 pm

Thanks yet again Steve.

Works like a charm :)

Of course!!
ozrebel
 
Posts: 18
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 32 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved