The Artima Developer Community
Sponsored Link

PHP Buzz Forum
HOWTO: Mimic Formmail

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Forum One

Posts: 118
Nickname: forumone
Registered: Sep, 2004

Forum One is consulting firm specializing in helping non-profits improve their online presence.
HOWTO: Mimic Formmail Posted: Sep 14, 2004 9:19 AM
Reply to this message Reply

This post originated from an RSS feed registered with PHP Buzz by Forum One.
Original Post: HOWTO: Mimic Formmail
Feed Title: Syntax Framework
Feed URL: http://blog.syntaxcms.org/rss.php?version=0.91
Feed Description: Finally, a place to answer Syntax questions
Latest PHP Buzz Posts
Latest PHP Buzz Posts by Forum One
Latest Posts From Syntax Framework

Advertisement

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

Read: HOWTO: Mimic Formmail

Topic: Sailing under a new flag Previous Topic   Next Topic Topic: Parsing non-well-formed XML documents considered harmful ...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use