Magento – Success message in popup

extensionsmagento-1.9popupsuccess-message

I have a frontend form in my custom module. On submitting the form,I want to display the success message in a popup with some custom content. How is it possible? Please help.

This is my controller.

public function formAction()
{
    if ($this->getRequest()->getPost()){
    //My Action
    // Mage::getSingleton('core/session')->addSuccess('Your Request has been sent');
    $this->_redirect("*/");
}

This is my phtml

<form id="test_sample_form" method="post" action="<?php echo $this->getUrl('module/controller/action') ?>">
    <fieldset class="group-select">Test Fields</fieldset>
</form>

I want to display the success message in a popup. Please help.

Best Answer

Submit the form via ajax

Use this script in your phtml:

<script type="text/javascript">
function callAjax(){ 
     jQuery.ajax({
        type    : "POST",
        url     : "<?php echo Mage::getUrl('module/ctrlr/action'); ?>",
        data    : jQuery('#test_sample_form').serialize(),
        dataType: "json",
        complete: function (data) {
            callpopup();
            document.getElementById("test_sample_form").reset();           
        },
    });
}
function callpopup(){ 
    jQuery.fancybox(
        '<p>Content!!!!!</p></br>',
        {
            padding:15,
            closeBtn:true
        }
    );
}

</script>
Related Topic