0

I want to show Magento all success/error message as alert or in a modal. Is there any way to do that?

1
  • Is there a reason for that? as if you keep showing success/error messages with modal, browsers will give the user option to block them. So after 2-3 modal, all of your modals on the site will be blocked if the user ask for.
    – Korbin
    Commented Jul 29, 2019 at 11:30

1 Answer 1

0

You can use this code for showing a message as Modal to your phtml file

<button type="submit" id="gotoreviewform" class="action submit primary write-action"><span>Click to Open</span></button>
<div id="popup-mpdal" style="display: none;" >
    <div class="message info notlogged" id="review-form">
        <div>
            <?php /* @noEscape */ echo __('Popup Modal Message!') ?>
        </div>
    </div>
</div>
<script type="text/javascript">
require(['jquery', 'Magento_Ui/js/modal/modal'], function($, modal){

var options = {
    type: 'popup',
    responsive: true,
    innerScroll: true,
    buttons: [{
        text: $.mage.__('Continue'),
        class: '',
        click: function () {
            this.closeModal();
        }
    }]
};
var popup = modal(options, $('#popup-mpdal'));

$(document).ready(function(){

    $("#gotoreviewform").click(function(){
        $('html, body').animate({
            scrollTop: $("#review-form").offset().top
        }, 1000);

    $("#popup-mpdal").modal("openModal");
});
});
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.