One of the task's we're often asked to do is save input from a form to the database and also send a notification message to a recipient. Recently I had to do that and include the record's data as part of the email message. While it's easy enough to build a custom message each time, the following solution builds the message body based on a defined view for your datatype. You'll need a newer copy of the metadata.pxdb_view class as I had to add a method to it allowing you to create a pxdb_view object based on the datatype id and view name. The main benefit to this approach, beyond it's flexibility is that we can add new fields to our view and the email sent out will automatically include those too without further intervention on your part.
if( $rec_id = $adm->save() )
{
pxdb_import( 'content.output.pxdb_record' );
pxdb_import( 'metadata.pxdb_view' );
// success! -- $rec_id is saved (or added) record id
$view = "success"; // for redirection later
// now get the just saved record back out of the database
$record = new pxdb_record( $rec_id );
// start building our email message
$msg = "A new feedback message has been sent:\n";
//get the 'public' view for the FEEDBACK datatype. We used
// this view to present a form to users.
$view = pxdb_view::fetch_object_view( DATATYPE_FEEDBACK, 'public' );
// build the rest of the message based on the fields used
$viewfields = $view->arr_typesfields();
while ( list(,$viewfield) = each( $viewfields ) )
{
$msg .= "\n ".$viewfield['displayname'].': '.$record->get_field( $viewfield['identifier'] );
}
// send it off to the intended recipient
mail( FEEDBACK_RECIPIENT, FEEDBACK_SUBJECT, $msg, "auto@".$_SERVER['SERVER_NAME']."\r\n" );
} // end if