0

I would like to add a "Contact us" form on each product; I've copied the contact form and added to the cms static block:

{{block type="core/template" form_action="/contacts/index/post/" template="catalog/product/view/form-personalizzazione.phtml"}}

The problem is, how can we change it so it doesn't redirect on contact page but it remains inside the product instead?

Inside phtml it starts with

<form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post">
1

You will have to either rewrite the Contact controller located at app/code/core/Mage/Contacts/controllers/IndexController.php

or alternatively create your own module and controller action, and use that as the form action.

So for example, change the form action to be something like:

{{block type="core/template" form_action="/modulename/index/post/" template="catalog/product/view/form-personalizzazione.phtml"}}

Within your Module controller postAction() method you could then either redirect back to the previous page or get the product from the registry and use it's Mage::registry('current_product')->getUrl() method data.

  • where exactly do I have to change/add Mage::registry('current_product')->getUrl() ? thanks – LaurenFrida Feb 22 '17 at 9:01
  • You can return a redirect to the product URL within the postAction() method. Essentially change where the returned redirects are in the normal post action – Richard Cripps Feb 22 '17 at 12:11
  • meaning from $this->_redirect('*/*/'); to Mage::registry('current_product')->getUrl(); ? – LaurenFrida Feb 22 '17 at 14:54
  • You should be able to do something like $this->_redirectUrl(Mage::registry('current_product')->getUrl()); – Richard Cripps Feb 22 '17 at 15:43
  • ok I've edited that, now I've added this block <block type="core/template" name="ProdottiController" form_action="catalog/product/view/form-personalizzazione.phtml" ></block> to catalog.xml and this {{block type="core/template" form_action="/ProdottiController/index/post/" template="catalog/product/view/form-personalizzazione.phtml"}} inside the custom tab but i get a 404 error, I think I made a mistake somewhere... – LaurenFrida Feb 22 '17 at 17:18

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.