Pregunta

I'm new to magento and I'm trying to create a module for an email form.

In classic MVC I would send the request to the Controller, but in Magento a controller is only responsible for one URL. So when I want to put my email form on the productpage I cant use the controller, is that right?

I inlcude my block element via layout xml in the productpage. So I have to validate my form und send the email in the class of my block element? Or would I have to write one or more helpers for that?

What is the magento way?

Thanks a lot. Sorry if my question is lame, but I'm a beginner and I want to learn the right way and I have seen so much tutorials with the wrong one.

¿Fue útil?

Solución

Just while submitting the form give action to controller like:

<?php echo Mage::getUrl()?>bpartner/index/mailbpartner

bpartner your module name
Index your controller name
mailbpartner your function in INDEX NAMED CONTROLLER FILE.


Get all details through POST and send mail like below + redirect with success

$to = "abc@abc.com";
                $dt = date('d-m-Y');
                $subject = "Become A Partner Details on date $dt";
                $mail = new Zend_Mail('utf-8');
                $mail->setBodyHtml($message)
                    ->setFrom($data['email'], $data['firstname'])
                    ->addTo($to, 'Site Admin')
                    ->setSubject($subject);
                try {
                    $mail->send();
                    Mage::getSingleton('core/session')->addSuccess('Mail sent successfully. We will contact you shortly');
                }
                catch(Exception $e) {
                    Mage::getSingleton('core/session')->addError('Unable to send email.');
                }
        $this->_redirect('bpartner');

Some above data are POST DATA which is self understandable

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top