Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Director::redirectBack()


Reply

2 Posts   2219 Views

Avatar
julian

19 March 2007 at 2:16am (Last edited: 19 March 2007 2:16am), Community Member, 17 Posts

Hi all ok I'm playing around with my first form. My question is --

in the example below, headers_sent(...) resolves to true so it does this almighty heavy weight 'redirecting to...'. How do I avoid this so that Director::redirect() calls header(...) instead.

I looked at PageComments and it does the same thing as below but doesn't do the heavyweight redirect; what have I done wrong that means that a simple form submission (could it get any simpler? A single action) sends header information.

thanks in advance!
J

code below
---

   /** an opinion is a gesture of thought by user -- marking as favourite or comment or whatever. */
   function OpinionForm() {
      $loggedInMember = Member::currentUser();
      
      // user is authenticated, so return elements in the form.
      // if the user isn't authenticated, we will require them to when they do something.
      if( $loggedInMember ) {
         $artwork = $this->data();
      
         // we have a member so find whether this artwork was marked as favourite and highlight as appropriate.
         // returns a ComponentSet.
         $members = $artwork->getManyManyComponents('MemberFavourites');
         if( $members ) {
            $memberMap = $members->map();
            
            // this is not marked as a favourite, so give them the option to do this
            if( !$memberMap[$loggedInMember->ID]) {
               $faveAction = new ImageFormAction('doMarkAsFavourite', 'Mark Artwork as favourite', 'mysite/images/fave_unselected.gif', 'mysite/images/fave_selected.gif' );         
            
            // ALREADY MARKED. Present option to unmark.
            } else {
               $faveAction = new ImageFormAction('doUnmarkFavourite', 'Remove from favourites list', 'mysite/images/fave_selected.gif', 'mysite/images/fave_unselected.gif' );                        
            }
         }
         
         $fields = new FieldSet();
         $actions = new FieldSet( $faveAction );
         return new Form( $this, 'OpinionForm', $fields, $actions );
         
         // TODO -- change icon based on state of favourite
      }
   }
   
   /** user chose this to be a favourite against currently authenticated member. */
   function doMarkAsFavourite() {
      $loggedInMember = Member::currentUser();
      
      if( $loggedInMember ) {
         $artwork = $this->data();
         $members = $artwork->getManyManyComponents('MemberFavourites');
         $members->add( $loggedInMember );
         Director::redirectBack();
      }
   }

Avatar
Sam

19 March 2007 at 11:36am Administrator, 685 Posts

Headers will have been sent because you've already outputted some text to the browser. Look for trailing newlines after the ?> tag in one of your PHP files, or a debug "echo" message.