3

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.

  • 1
    write add success message and call in popup block – Rama Chandran M Jul 3 '17 at 10:01
  • Sorry. I didn't understood. Could you please explain. – Vindhuja Jul 3 '17 at 10:02
  • i will provide code – Rama Chandran M Jul 3 '17 at 10:21
  • @Rama Chandran Is there any upadate? – Vindhuja Jul 3 '17 at 11:25
  • I am checking code.not success – Rama Chandran M Jul 3 '17 at 11:28
1

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>
0

Submit the form via ajax

        $.ajax({
        type: frm.attr('method'),
        url: frm.attr('action'),
        data: frm.serialize(),
        success: function (data) {
            // decode JSON data and load message in popup
        },
        error: function (data) {
            console.log('An error occurred.');
            console.log(data);
        },
    });

On the controller side return the value in JSON format, something like below

echo  '{"status":"true","message":"YOUR MESSAGE"}';
  • I have changed the form submission using ajax. But how is it possible to display the popup on ajax success.This is my script. complete: function(response) { alert("success"); jQuery.fancybox({ maxWidth : 450, maxHeight : 350, fitToView : false, width : '70%', height : '70%', autoSize : false, }); }, alert("success") is working. But popup is not loading. Please help. – Vindhuja Jul 4 '17 at 8:40
  • You need to trigger fancybox , check this stackoverflow.com/questions/13452197/jquery-fancybox-trigger – Rakesh Gangani Jul 4 '17 at 9:33

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.