0

A Magento 1.9 website worked perfectly with PHP 5.6.40, but the server (which I don't have access to) was upgraded to PHP 7.1 and the custom contact forms stopped working.

It does not give any error, however, the action of the form is not done correctly and redirects to a Login page that I have never seen. It was to send an email and redirect to a pdf.

Does anyone know what can it be?

The module that no longer works:

Controller

<?php
class Empresa_Liga_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }

    public function postAction()
    {
        $post = $this->getRequest()->getPost();

        if ($post){
            try {
                $name = $post["name"];
                $telefone = $post["telefone"];
                $email = $post["email"];
                $ddd = substr($telefone, 0, 2);

                $to = "comercial@empresa.com.br";

                $subject = "Novo Contato";
                $body .= "<p>Novo contato pelo formulario: 'A empresa liga pra você'</p>";
                $body .= "<p>Nome : " . $name . "</p>";
                $body .= "<p>Telefone  : " . $telefone . "</p>";
                $body .= "<p>Email  : " . $email . "</p>";

                $from = "empresa@gmail.com";

                $mail = Mage::getModel('core/email');
                $mail->setToName('Your Name');
                $mail->setToEmail(array($to,'marketing@empresa.com.br'));
                $mail->setBody(utf8_decode($body));
                $mail->setSubject($subject);
                $mail->setFromEmail($from);
                $mail->setType('html');// YOu can use Html or text as Mail format
                $mail->setBodyHTML(utf8_decode($body));  // your content or message

                $mail->send();

                Mage::getSingleton('core/session')->addSuccess('Sua solicitação foi enviada... Em breve entraremos em contato');
                $this->_redirect("agradecimento-a-empresa-liga-pra-voce");
                return;
            } catch (Exception $e) {
                Mage::getSingleton('core/session')->addError('Ocorreu um erro, tente novamente mais tarde');
                $this->_redirect('*/*/');
                return;
            }
        } else {
            $this->_redirect('*/*/');
        }
    }
}

config.xml:

<?xml version="1.0"?>
<config>
  <modules>
    <Empresa_Liga>
      <version>0.0.1</version>
    </Empresa_Liga>
  </modules>
  <frontend>
       <routers>
          <brochure>
              <use>standard</use>
              <args>
                 <module>Empresa_Liga</module>
                 <frontName>empresa-liga</frontName>
              </args>
           </brochure>
       </routers>
       <layout>
            <updates>
                <empresa_liga>
                    <file>brochure.xml</file>
                </empresa_liga>                
            </updates>
        </layout>
    </frontend>
  <global>
    <helpers>
      <module>
        <class>Empresa_Liga_Helper</class>
      </module>
    </helpers>
  </global>
</config>

Data.php

<?php
class Empresa_Liga_Helper_Data extends Mage_Core_Helper_Abstract
{
}
0

It was actually quite simple, I don't know why it wasn't a problem before. I found the solution here:

https://stackoverflow.com/questions/57409768/cannot-retrieve-post-data-because-of-301-moved-permanently-error

in the html of my form it was like this:

<form action = "/empresa-liga/index/post" id ="brochureform" method = "post">
..........
</form>

I switched to

<form action = "/empresa-liga/index/post/" id = "brochureform" method = "post">
..........
</form>

| improve this answer | |

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.