Pausing PHP code execution with alert box

Associate
OP
Joined
6 Mar 2009
Posts
495
I understand, your wanting to validate the outcome as the user enters the result and then you'll save it on submit.

But what we'retrying to explain is that you really don't need to, you're over complicating the process and increasing the number of requests required for something that can be done in a single POST.

Yea I probably am over complicating things! lol I initially wanted to add a line into my single POST where I could almost pause the code execution and let the use click ok or cancel.

So the user clicks submit, it returns what the outcome is and then prompts the user to continue or cancel. If ok or continue is clicked then the rest of the code would be executed and the data submitted to the database.

If I could add something like the following into the php code to prompt the user would be perfect:
Something like that jester mentioned:

Code:
confirm('You sure, mate?')
 
Associate
Joined
19 May 2003
Posts
1,390
Location
Saltaire, West Yorkshire
You can and people have been hinting at how you could do this, I mean all you really need is to add an additional step between confirming the results and storing them;

1. User submits form.
2. Return confirmation of results.
3. User confirms submission.
4. Save to DB.

Simple.
 
Associate
OP
Joined
6 Mar 2009
Posts
495
You can and people have been hinting at how you could do this, I mean all you really need is to add an additional step between confirming the results and storing them;

1. User submits form.
2. Return confirmation of results.
3. User confirms submission.
4. Save to DB.

Simple.

Ok I have got the confirmation box to appear when I want it, but if I click on cancel it still submits the data to the database!

Here is what I used:
Code:
echo '<script type="text/javascript">
confirm("Are you sure!");
</script>';
 
Associate
Joined
4 Feb 2011
Posts
580
Location
Halifax
Ok I have got the confirmation box to appear when I want it, but if I click on cancel it still submits the data to the database!

Here is what I used:
Code:
echo '<script type="text/javascript">
confirm("Are you sure!");
</script>';

You need to assign confirm to a variable.

Code:
var r = confirm("Are you sure!");
if(r === true){
    //do_whatever();
}else{
    return false;
}
 
Caporegime
Joined
18 Oct 2002
Posts
29,491
Location
Back in East London
Ok I have got the confirmation box to appear when I want it, but if I click on cancel it still submits the data to the database!

Here is what I used:
Code:
echo '<script type="text/javascript">
confirm("Are you sure!");
</script>';

See my first reply (#6) in this thread. Note the "return" in the onclick event. If that snippet of code returns false, the form will not post (submit).

If you're not assigning it to the onclick event of the submit button, and wish for something else to submit it, then you'll need trigger the submit function of the form.
 
Back
Top Bottom