Magento – Form submit on same page

formsmagento-1.9redirect

I want to submit my form on the same page :

<form action="<?php echo Mage::helper('checkout/cart')->getAddUrl(Mage::registry('current_product')); ?>" method="post" id="seller_addtocart_form1" class="ma">
    <button id="<?php echo $seller->getMpassignproductId() ?>" class="button btn-cart customaddtocart" title="<?php echo $this->__('Add to Cart')?>" onclick="<?php echo $currentUrl = Mage::helper('core/url')->getCurrentUrl();?>">
    <?php echo $this->__('Add to Bag')?></span></span></button>
</form>

Form is submitted in cart page so I use onclick() function in button but it won't work.

Can anyone please guide me, what's wrong in my code ?

Best Answer

You need follow below steps

  • add return_url as a new hidden input field to from

<input type="hidden" name="return_url" value="<?php echo $currentUrl = Mage::helper('core/url')->getCurrentUrl();?>" />

  • and remove onclick="<?php echo $currentUrl = Mage::helper('core/url')->getCurrentUrl();?>" for form submit

<button id="<?php echo $seller->getMpassignproductId() ?>" class="button btn-cart customaddtocart" title="<?php echo $this->__('Add to Cart')?>" type="submit">

from

<button id="<?php echo $seller->getMpassignproductId() ?>" class="button btn-cart customaddtocart" title="<?php echo $this->__('Add to Cart')?>" onclick="<?php echo $currentUrl = Mage::helper('core/url')->getCurrentUrl();?>">

Update:

Use this it should works:

 <form action="<?php echo Mage::helper('checkout/cart')->getAddUrl(Mage::registry('current_product')); ?>" method="post" id="seller_addtocart_form1" class="ma">

<input type="hidden" name="return_url" value="<?php echo $currentUrl
  =  Mage::helper('core/url')->getCurrentUrl();?>" />

    <button id="<?php echo $seller->getMpassignproductId() ?>" class="button btn-cart customaddtocart" title="<?php echo $this->__('Add to Cart')?>" type="submit"><span><span><?php echo $this->__('Add to Bag')?></span></span></button></form>
Related Topic