I'm trying to replace the normal browser alerts with a Sweet Alert one, more however the normal alerts after validating a condition in a function that is in a different file than index.php, but that is already linked by require_once "";
reloading the page and shows me the alert, the content of my page does not appear until the alert is closed. I show image as it is.
Until I accept, the page doesn't finish loading... I would like my content not to disappear while the alert is displayed.
I already included the Sweet Alert script in my project in the index, I did a console test of how I want the alert to appear in my index after validating the condition in my other file which I called functions.php. From the console doing the test...
I tried to replace the normal alert code in the functions.php page but when it validates the condition it doesn't show me any alert when it should. I appreciate if you can help me about how I do it, I've been searching until now I can't find how to do it.
I currently have the following code.
function operacion(){
if (condicion) {
sentencias a ejecutar si la condicion se cumple...
} else {
echo "<script>
Swal.fire({
icon: 'error',
title: 'Oops...!',
text: 'Operación inválida, el puesto ya ha sido vendido.',
})
window.location= 'index.php'
</script>";
}
}
But nevertheless the alert is not executed...
When checking the console I am getting the following error, "index.php:30 Uncaught ReferenceError: Swal is not defined at index.php:30"; If I go to see the error through the console it shows me this...
In that line is where I have the opening of my PHP tag in the index....
Thank God I have found the root of the problem and I have managed to solve the failure. The problem was that I was linking to the Sweet Alert2 repository (I think that's what it's called) at the very end of my document before the closing tag.
I found this on the web and decided to implement it in my project, linking both the JS and CSS files of Sweet Alert but in the Head of my Index document.
https://github.com/realrashid/sweet-alert/issues/3 .
In such a way then that the beginning of my code was in such a way.
With this I managed to solve my problem.