conditional outcome after saving a record

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

conditional outcome after saving a record

Postby ststoddard » Mon Nov 05, 2007 4:25 pm

Depending on a value entered in a form, I want the app to go to different places upon a user clicking 'Save'. Usually I have no problem with this. However, in this instance, it doesn't quite work.

Code: Select all
function afterInsert(&$record){
      $app =& Dataface_application::getInstance();
        $auth =& Dataface_AuthenticationTool::getInstance();
        $user =& $auth->getLoggedInUser();     
        $lc = $record->val('location_code'); // same as dataframe$val
        //print $lc;
        $date = $record->strval('date');
        $status = $record->val('status');
        $query = & $app->getQuery();
        $eid = trim($query['eid'],"=");
        if ( strpbrk($lc,"X") ) $msg = "El codigo de casa usado en el registro no se encuentra en la base.  Se ha indicado que la ficha debe ser revisada.";
        //print $date;
        if ( $user ) {
           if ( $status == "WORKED" ) {
         header("Location: index.php?-table=House_survey&-action=new_related_record&location_code=$lc&date=$date&-relationship=caracteristicas&--msg=$msg");
         exit;
         } else {
         //This isn't working!  Doesn't make sense.  The app goes to house_survey list view, not the new related record form.
         header("Location: index.php?-table=Entomology&-action=new_related_record&eid=$eid&-relationship=encuesta");
         }
      }
   }


Basically, when status is not 'WORKED' this should loop back to create a another version of the same form, with the same relation. However, it kicks me out to the list of related records already entered.

???
S. T. Stoddard
ststoddard
 
Posts: 56
Joined: Mon Nov 05, 2007 4:10 pm
Location: Davis, CA

Postby shannah » Mon Nov 05, 2007 4:42 pm

This sort of thing is better handled in the after_action_edit() method, as the beforeInsert() trigger is called whenever a record is inserted through the API. (many records could be inserted in a single request).

Nonetheless this code should work. You may want to try adding an exit call after your header() (you did that for the first case but not the second).

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 35 guests

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