Mulgard Mulgard - 1 year ago 78
PHP Question

PHP: Confirmation Dialog without using JavaScript?

I have a very simple form:

<form action="system/web/push.php" method="post">
<div class="row">
<div class="col card_input_push card_input_push_language">
<select name="<?php echo PARAM_PUSH_LANGUAGE; ?>">
<?php echo get_languages($mysqli); ?>
<div class="row">
<div class="col card_input card_input_push">
<input type="text" name="<?php echo PARAM_PUSH_TITLE; ?>" placeholder="<?php echo $language_array[LV_PUSH_INPUT_TITLE]; ?>"<?php echo set_value(PARAM_PUSH_TITLE); ?>required/>
<div class="row">
<div class="col card_input_push card_input_push_message">
<textarea name="<?php echo PARAM_PUSH_MESSAGE; ?>" placeholder="<?php echo $language_array[LV_PUSH_INPUT_MESSAGE]; ?>"<?php echo set_value(PARAM_PUSH_MESSAGE); ?>required></textarea>
<div class="row">
<div class="col text-center card_input_push card_button_push_send">
<button class="btn btn-default" type="submit" name="<?php echo REQUEST_SEND_GCM; ?>" value="<?php echo $language_array[LV_PUSH_INPUT_SEND]; ?>"><?php echo $language_array[LV_PUSH_INPUT_SEND]; ?></button>

When i now press the submit button i dont want the post to perform instantly. I first want a confirmation dialog to show up with yes or no answers and only if the user says
i want the post action to be performed.

What i NOT want is to use
. Is there a way to do that?


Thank's for the answers. To satisfy all respondents i would like to tell you, why i dont want to use
. The answer is simple. I have no idea about
. I never have used it before but the project im working on (as always) has to be finished ASAP. That's the only reason.

Answer Source

Yes there is a way, use GET (not POST) the first time, on the PHP file check if GET was used and if so generate a form that sends confirmation form back to the user. Then make confirmation form to submit using POST and you are done.

 if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    // generate confirmation form
 }elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // process your data

If anyone has access to a book called Head First PHP-MySQL they cover a similar example on page 280.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download