Search code examples
phpsilverstripesilverstripe-4

How to add a header to form url after redirected back?


How would I add header to the response to this?

public function handleDonate($data, $form)
{
    $donate = DonationForm::create();
    $donate->FullName = $data['FullName'];
    $donate->Amount = $data['Amount'];
    $donate->Email = $data['Email'];
    $donate->Message = $data['Message'];
    $donate->SponsorshipPageID = $this->ID;
    $donate->write();
    return $this->redirectBack();
}

Solution

  • redirectBack() returns a HTTPResponse object, so you can manipulate that before you return it:

    return $this->redirectBack()->addHeader('X-Foo', 'Bar');