lipis / bootstrap-sweetalert

:cake: A beautiful "replacement" for JavaScript's alert ⛺
https://lipis.github.io/bootstrap-sweetalert/
MIT License
2.1k stars 503 forks source link

Replacing Plain Javascript with better looking SweetAlert in PHP Form #87

Open marcoczen opened 2 years ago

marcoczen commented 2 years ago

Hi,

Currently in my PHP / HTML / BootStrap form I have a functional plain Javascript Confirmation Dialogs ( Proceed ? - Yes / No ) as follows;

:: JS Code ::

function actionConfirm(msg1) {

    if (confirm(msg1)) { 
        return true;
    } else {    
        return false;    
    }

 }
 //end of  actionConfirm

    const elems = document.getElementsByClassName('confirmProceed');

    Array.prototype.forEach.call(elems, (elem) => {    

        elem.addEventListener('click', (event) => {

           if ( !actionConfirm('Proceed with Action?') ){
                event.preventDefault();
           } 

        });

    }); // end Array.prototype.forEach 

My php form is submitted by a button of type 'submit' and the javascript function by a class 'confirmProceed' as shown below:

:: PHP Form snippet ::

<button type="submit" class="btn_custom confirmProceed" 
             name="button_delete"  value="delete" 
             title="Delete Item" >Delete</button>  

Any idea how i can use the SweetAlert Dialog in the above code to provide better looking Confirmation Dialogs without removing the button of type 'submit' ?