Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP version of confirm() of JavaScript

Is there a PHP version of JavaScript's confirm() function?
If not, what are my other options or how do I make something similar to the confirm()?


1 Answers

Because PHP is a server-side language (all the PHP code is executed on the server, and the output of the code is sent to the client), you'd have to make an HTML form with OK/Cancel buttons that would submit to your PHP page. Something like this:

confirm.php:

<p>Are you sure you want to do this?</p>

<form action="page2.php" method="post">
    <input type="submit" name="ok" value="OK" />
    <input type="submit" name="cancel" value="Cancel" />
</form>

page2.php:

<?php

if (isset($_POST['ok'])) {
    // They pressed OK
}

if (isset($_POST['cancel'])) {
    // They pressed Cancel
}

?>
like image 187
Paige Ruten Avatar answered Nov 21 '25 11:11

Paige Ruten