Click to See Complete Forum and Search --> : [RESOLVED] Browser Pop-Up Confirm?


Channel5
07-12-2009, 11:28 PM
For those of you who have used Hotmail or various other services... you know how when you select delete (for example, to delete an email), there's a small "pop-up" type thing that asks if you're sure: yes or no?

How would I call that in php whenever a user would delete an entry before it would actually process the update query?

devinemke
07-13-2009, 12:07 PM
<html>
<head>
<title>test</title>
<script type="text/javascript" language="javascript">
function confirm_delete()
{
var confirmed = confirm("CONFIRM: Are you sure you wish to delete this?");
if (confirmed) {return true;} else {return false;}
}
</script>
<body>

<?php
if (!isset($_POST['submit']))
{
echo '
<form action="" method="post" onsubmit="return confirm_delete();">
<input type="submit" name="submit" value="delete something">
</form>
';
}
else
{
// delete SQL here
echo 'deleted';
}
?>

</body>
</html>

Channel5
07-13-2009, 06:19 PM
Awesome! Thanks.

I'm very grateful to this site. I've learned so much from this community.

Channel5
07-16-2009, 08:20 PM
Is there a way to do this without using a submit button -- or more specifically, running the form using a link instead?

For example:


echo '<a href="?action=go">Click</a>';

if($_GET['action'] == 'go'){
// execute pop-up, then
// run code action
}

johanafm
07-17-2009, 05:39 AM
<a href=javascript:dostuff()>click</a>

function dostuff() {
// as before

// either
if (confirmed)
document.location = "whatever you wanted in your href to start with";

// or
document.forms[0].submit();
}


Seems pointless to click a link that sends something to the server, which returns code to display a popup for confirmation, which is then sent to the server. That's one page refresh too many if you ask me. If this approach is really necessary, use ajax.

Also, clicking a link to send a form is generally a really bad idea as well. It's "always" (as close to always that other ways doesn't matter) a button used to submit the form. What you'd achieve is most likely to confuse users, or even just force them to think. Go with a submit button and they won't have to.

Channel5
07-17-2009, 08:10 PM
Maybe I'm gettng the order of the code mixed up.

But basically what I want to do is have the pop-up show when a user clicks a delete link after checking the box(es) of the entries they want to delete.

Since Microsoft does it this way with their hotmail and live email accounts, along with other major companies, is it really that strange or confusing?

Weedpacket
07-18-2009, 01:39 AM
Why would you want a link to work like a button? Apart from the breach of usability conventions (links work like links, buttons work like buttons - links take you places, buttons do things), I've seen cases where "delete links" led to everything being deleted accidentally.


You can of course use CSS to make a button look like a link. You can make it look like a dancing gorilla if you want. CSS is nice like that.

Or if you still want to use a link, have a look at Microsoft's hotmail and live email account pages, or those other major companies, and see how they do it.

Channel5
07-18-2009, 05:37 AM
Or if you still want to use a link, have a look at Microsoft's hotmail and live email account pages, or those other major companies, and see how they do it.

Maybe I asked the question because I don't know how they did.

Perhaps that was the whole point of my question. :rollseyes:

I know what I want. I know why. I was asking for help, not the reasons why I shouldn't do this or do that.

I swear some people make coding into their personal religion. ;)

Weedpacket
07-18-2009, 08:29 AM
I don't know how they did.Like I said, have a look. It's on your browser, isn't it?

religionNo, just profession. I'll bet ye don't even know the difference between a safe and an idempotent request method ;)

Channel5
07-18-2009, 03:42 PM
I guess a giant like Mircrosoft clearly doesn't classify as professional.

Maybe I'll take a look at hotmail's code when they send me the script.

Safe or idempotent request? That's with or without a condom, right?

Weedpacket
07-19-2009, 07:10 AM
when they send me the script.What, you mean like when you load the page?