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.

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

3 Answers 3

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"}';
2
  • 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, 2017 at 8:40
  • You need to trigger fancybox , check this stackoverflow.com/questions/13452197/jquery-fancybox-trigger Jul 4, 2017 at 9:33
0

like this you can delete everything in popup and then show success content in the same popup

 if ($(this).validation('isValid')) {
                $.ajax({
                    url: $(this).attr('action'),
                    data: $(this).serialize(),
                    dataType: 'html',
                    type: 'POST',
                    showLoader: true,

                    /**
                     * Success function
                     */
                    success: function () {
                        $('#form-div-element').remove();
                        $('#devnewsletter-validate-detail').html(contentOptions.success);
                    }
                });
            }

I take successContent from admin page so for me its like

contentOptions = {
                success: this.options.successContent
            };

I am using popup widget.

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.