0

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); ?>
            </select>
        </div>
    </div>
    <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>
    </div>
    <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>
    </div>
    <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>
        </div>
    </div>
</form>

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 yes i want the post action to be performed.

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

EDIT

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

4
  • 3
    You need JS for this. JS is what you use to make a static HTML-page interactive. All PHP-code is executed before the HTML-page even reaches the client and can't send things like confirmation dialogs. Why don't you want to use JS? Commented Jun 3, 2016 at 9:52
  • but why you don't use javascript for that? any reason? Commented Jun 3, 2016 at 9:53
  • Question Is: Why Don't You Want To Use Javascript ? Commented Jun 3, 2016 at 10:04
  • Don't want to use JS ... hmmm you could get retro and write it so it requires really old versions of Internet Explorer and use VBScript if you were, you know, really perverse. Commented Jun 3, 2016 at 10:04

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

8 Comments

Technically that would work (kinda) but it sounds terrible; submitting the form to the server just to generate a dialogue box?
@CD001 that's exactly what OP wants. You can create confirmation form either with javascript or with PHP.
Actually... the OP says: "i dont want the post to perform instantly. I first want a confirmation dialog to show up". Btw, wouldn't be easier to always use POST but have a hidden field saying if it is confirmed or not? However, both ways are, in my opinion, bad design across the board.
Then he needs two forms; the first to gather the data and the second to say "are you sure"
I think the best thing would be for the OP to explain why he doesn't want to use JS. Then we might come up with a better alternative.
|
1

Maybe you could do something like this, with some css for design your dialog.

change your form with :

<form action="this_page">

If you submit, you call this page, display the dialog with a form, and when you submit with second form, you post to your needed php file.

if (isset($_POST['your_submit'] )) {
     echo "<yourdialog>";
     echo "<form action="system/web/push.php">";
     echo "content";
     echo "<submit yes>";
     echo "</form>";
     echo "</yourdialog>";
}

Comments

1

Your workflow is:

  • gather form data
  • send to server
  • get confirmation that that's what the user wants.
  • if yes then process data.

If you want to do that all via php then the server's handling the full load, so you'll want two forms, one to collect and one to confirm. And you'll want to store the first form's data so you can process it according to the second form's result. A bit old fashioned but not difficult.

2 Comments

What if the question is "are you happy to send this data to our server?" - it's a bit late to ask that if they've already had to send the data to the server to generate the dialogue box...
that's the price you pay for using server side validation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.