0

I'm working on Magento 1.7 (I know - in process of upgrading to 2) and made a custom form as a Magento plugin. Everything upto the redirect works - but I'm not sure why or how to debug.

This is my sendEmail() function:

$mail = Mage::getModel('core/email');

$mail->setBody($this->emailHtml($code));
$mail->setFromName('MPW Site');
$mail->setToEmail($to);
$mail->setSubject('Thank You For Registering Your Atom Battery');
$mail->setType('html');

try {
    $mail->send();
    Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
    $this->_redirect('custom-page-?code='. $code);
} catch (Exception $e) {
    Mage::getSingleton('core/session')->addError('Unable to send');
}

However, this snippet results in a White Screen of Death - so I put this in my index.php file to try and debug:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(-1);

register_shutdown_function("fatal_handler");
function fatal_handler() {
    $error = error_get_last();
    echo("<pre>");
    print_r($error);
}

but still - nothing on screen. var/log also hasn't got any files with a last edit timestamp of today on so I'm really not sure how/why the code is going askew. From what I read online, that redirect should work.

How do I redirect to a CMS page after my form submits?

0

I found a solution.

$this->_redirect() is a method only available to classes extending Mage_Core_Controller_Front_Action - the code I had lived inside a Block class. Hence no access to $this->_redirect().

Still weird how the debug function and logging didn't pick up on it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.