Oliver Spiesshofer wrote:
Hi,
I want to make a standard-function that handles "Are you sure"-type
questions.
In my idea it should look something like this:
<code>
Function deleteitem($item)
{
if (checkback("Are you sure you want to delete this item?"))
{
# delete SQL function code
}
}
</code>
where the code of the function checkback will ask a simple yes/no
question. As far as I found out, this is difficult since you need two
steps to get an answer from a html page. If there any standard way how to
do this?
thanks
Oliver
Hi Oliver,
I alway handle that type of 'are you sure' in Javascript.
Just create a button instead of a submit in the form and call confirm:
<input type="button" value="delete" onClick="checkDelete()">
function checkDelete(){
if (confirm("are you sure?")) {
document.forms["formnamehere"].submit();
}
}
If you want PHP to ask the question, you are stuck with an extra
intermediate page, because PHP can only communicate with a client by giving
HTML with the question in it.
About 'standard way': Is there a standard way to walk?
It is just so basic that I don't think it is worth creating a framework for.
Try something like this as intermediate page:
Are you sure?
<br>
<a href="thispage.php?suredelete=Y">Yes</a>
<br>
<a href="thispage.php?suredelete=N">No</a>
<?
if (isset($_GET["dodelete"])) {
if ($_GET["dodelete"] == "Y") {
// deletesql here.
}
}
?>
Hope that help.
Regards,
Erwin Moller