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

Director::redirectBack()


Go to End
Reply


2 Posts   2438 Views

Avatar
julian

Community Member, 17 Posts

19 March 2007 at 2:16am

Edited: 19/03/2007 2:16am

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

Administrator, 685 Posts

19 March 2007 at 11:36am

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.