<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.7.2" -->
<rss version="2.0">
    <channel>
        <title>beforeSave[ Search for &quot;&quot;]</title>
        <description></description>
        <link>http://xataface.com/wiki/index.php?-action=single_record_search&amp;-table=wiki&amp;page_id=%3D109&amp;-cursor=0&amp;-skip=0&amp;-limit=30&amp;-mode=list&amp;--subsearch=</link>
        <lastBuildDate>Sat, 18 May 2013 18:00:45 +0100</lastBuildDate>
        <generator>FeedCreator 1.7.2</generator>
        <item>
            <title>beforeSave</title>
            <link>http://www.xataface.com/wiki/beforeSave</link>
            <description>&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Field&lt;/th&gt;&lt;th&gt;Value&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page name&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;beforeSave&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page id&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;109&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page title&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;beforeSave Trigger&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Content&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;&lt;p&gt;Back to &lt;a href=&quot;/wiki/Delegate_class_methods&quot;&gt;Delegate class methods&lt;/a&gt;&lt;/p&gt;

&lt;table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;&lt;tr&gt;&lt;td&gt;
&lt;div id=&quot;toc&quot;&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc0&quot;&gt;Synopsis&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc1&quot;&gt;Method Signature&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 2em;&quot;&gt;&lt;a href=&quot;#toc2&quot;&gt;Parameters&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 2em;&quot;&gt;&lt;a href=&quot;#toc3&quot;&gt;Returns&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc4&quot;&gt;Examples&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 0em;&quot;&gt;&lt;a href=&quot;#toc5&quot;&gt;See Also&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;


&lt;h3 id=&quot;toc0&quot;&gt;Synopsis&lt;/h3&gt;
&lt;p&gt;The beforeSave trigger can be implemented in any table's Delegate Class Methods&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=delegate_class&quot;&gt;?&lt;/a&gt; to perform functionality that should be run *before* a record of that table is saved.  This is a useful place to insert additional field values depending on the input of the save record form.&lt;/p&gt;

&lt;p&gt;This method is called both when records are inserted and when existing records are updated.  Some other triggers include beforeInsert&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=beforeInsert&quot;&gt;?&lt;/a&gt;, beforeUpdate&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=beforeUpdate&quot;&gt;?&lt;/a&gt;, afterSave&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=afterSave&quot;&gt;?&lt;/a&gt;, afterInsert&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=afterInsert&quot;&gt;?&lt;/a&gt;, and afterUpdate&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=afterUpdate&quot;&gt;?&lt;/a&gt;, which do what you might expect.&lt;/p&gt;


&lt;h3 id=&quot;toc1&quot;&gt;Method Signature&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;function beforeSave( Dataface_Record $record);&lt;/code&gt;&lt;/pre&gt;


&lt;h4 id=&quot;toc2&quot;&gt;Parameters&lt;/h4&gt;
&lt;ol&gt;
    &lt;li&gt; &lt;strong&gt;$record&lt;/strong&gt; - The record that is about to be saved.  This is a &lt;a href=&quot;http://dataface.weblite.ca/Dataface_Record&quot; onclick=&quot;window.open(this.href, '_blank'); return false;&quot;&gt;Dataface_Record&lt;/a&gt; object.&lt;/li&gt;
&lt;/ol&gt;


&lt;h4 id=&quot;toc3&quot;&gt;Returns&lt;/h4&gt;
&lt;ol&gt;
    &lt;li&gt; &lt;a href=&quot;http://dataface.weblite.ca/Dataface_Error&quot; onclick=&quot;window.open(this.href, '_blank'); return false;&quot;&gt;Dataface_Error&lt;/a&gt; on failure (if you want to cancel the save).&lt;/li&gt;
&lt;/ol&gt;


&lt;h3 id=&quot;toc4&quot;&gt;Examples&lt;/h3&gt;
&lt;p&gt;Given a table named &amp;quot;people&amp;quot;, suppose we wanted to automatically populate a field named &amp;quot;full_name&amp;quot;  with the concatenation of the &amp;quot;first_name&amp;quot; and &amp;quot;last_name&amp;quot; fields.  (Note you could also achieve a similar thing by making a calculated field for &amp;quot;full_name&amp;quot;, but for this example, we assume that we actually want to store this in the database.&lt;/p&gt;

&lt;p&gt;We create a beforeSave() trigger that automatically updates the &amp;quot;full_name&amp;quot; field every time the record is saved.&lt;/p&gt;

&lt;p&gt;In the &amp;quot;people&amp;quot; table delegate class (i.e. tables/people/people.php) 
&lt;pre&gt;&lt;code&gt;class tables_people {
    function beforeSave($record){
        $record-&amp;gt;setValue('full_name', 
            $record-&amp;gt;val('first_name').' '.$record-&amp;gt;val('last_name')
        );
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;/p&gt;


&lt;h2 id=&quot;toc5&quot;&gt;See Also&lt;/h2&gt;
&lt;ul&gt;
    &lt;li&gt; &lt;a href=&quot;http://www.xataface.com/documentation/tutorial/getting_started/triggers&quot; onclick=&quot;window.open(this.href, '_blank'); return false;&quot;&gt;Triggers section of the Xataface Getting Started Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Keywords&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;triggers, beforeSave,&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Language&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;en&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description>
            <author>beforeSave</author>
        </item>
    </channel>
</rss>
