I’d like to be able to set the HTTP status code from my plug-in. I’m invoking it from prototype’s Ajax.Updater method, which will behave differently depending on whether it gets a 200 OK or 4xx/5xx error code back from the server. When I tested my code outside of an ExpressionEngine context, the following worked fine:
if ($email->Send()) {
$this->return_data = 'Email sent!';
} else {
header('HTTP/1.0 400 Bad request');
$this->return_data = 'There was a problem sending your message. Please try again.';
}
However, once I put that inside my plugin and invoked it from a template, it stopped working. It looks like EE is overriding my 400 status code with its own 200 OK status code. Can I get around that?
Thanks, Ben
Hi, Ben – first a disclaimer: I’m not a programmer. But! This recently came up in regards to forcing a 404 header on a given template, and in the end Derek posted several code snippets. The last solution was this one but you may wish to review the entire thread.
I hope that is of some help to you, at least. =)
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.