I have a PHP code which does bunch of things so to keep things simple I have removed the unnecessary code from it.
In the below if block I need to create a pop up window with that $message on it and it should have ok and cancel button on it. Once I click ok button I need to execute some other php code in the same file if possible (or it can be another PHP file as well) and if I click cancel button then it should not do anything.
Below is my test.php file-
<?PHP
// ..... some other code
if (!isset($_SESSION['admin'])) {
$text = "hello world";
// create a pop up window with $message on it along with "ok" and "cancel" button
echo "<script type='text/javascript'>confirm('$text');</script>";
}
// ..... some other code
?>
I can have either JS modal, or an HTML/CSS modal anything works as long as I can have some actions on ok and cancel button. Is this possible to do? I tried looking around but not able to figure it out on how to do this.
Update:
Below is my updated hello.php file where I used Oliver suggestion. I tried with below code where I have a javascript function secondUser but it shows popup as Sad :( - invalid session once I click ok button.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" type="text/javascript"></script>
<script>
function secondUser() {
$.post( "ajax/test.php", function( data ) {
if (data.success) {
alert(data.message);
} else {
alert("Sad :( - invalid session");
}
});
}
</script>
<?PHP
// ..... some other code
if (!isset($_SESSION['admin'])) {
$text = "hello world";
// create a pop up window with $message on it along with "ok" and "cancel" button
echo "<script type='text/javascript'>if (confirm('$text')) { secondUser(); };</script>";
}
// ..... some other code
?>
Now I am not able to figure it out what is wrong in my above code? I just want to execute my test.php using ajax in my other php file.
confirmand simply add alocation.hrefpointing to it. if it's a post you'd need a form or make an xmlhttprequest using post.confirm() ? redirect : ''