On Thursday, June 27, 2002, at 12:48  PM, Shane wrote:

> I would like your opinions on the best way to implement an "Are You 
> Sure You Want To Do This?" dialog for an Admin user when they go to 
> delete a record in a DB.
>
> Do you find that a whole page is usually required for this, or does 
> anyone have any nice pop up solutions for such a query.
>
> Sure... I hate doing these things too, but when Joe Big Boss gets a bit 
> trigger happy and kills some data he mistakenly thought was a different 
> record. You KNOW who is going to hear about it from on high.  :^)

It's such a pain in the ass, isn't it?  Unless you're using JavaScript, 
it's like an extra step, and you probably want to re-display the data 
that's being altered, so you really end up having to make another whole 
page in order to do it.

One way that I like to do it is this:

Most of my scripts are really giant switch() statements, and depending 
on the "action" variable passed in the querystring, different things 
happen.  So...

http://www.domain.com/addrecord.php?action=intro

The switch statement reads the $_GET['action'] variable and knows to go 
to the "intro" block, where I display the instructions for the page.  
The next one would be

http://www.domain.com/addrecord.php?action=form

and is accessible from a hyperlink generated in the "intro" section.  
This displays  a form that lets the user do some data-changing 
operation.  The form is of POST method, and the form's own action 
attribute is

$_SERVER['PHP_SELF'] . "?action=confirm"

So now all the user input is in the $_POST array and the "action" 
variable's value is "add", so the master switch() statement sends the 
code to the "add" section.  What happens here is, some checks are done 
on the data to see if it is valid, and if it is valid, the changes are 
echoed back to the user as a "confirm" page with a button to resubmit 
one final time (all the values are thrown into hidden variables).  
However, note that if the input is NOT valid, we don't have to re-do the 
code to display the form again, because we can just echo back the error 
messages and use the switch() statement's ability to "drop down" to the 
next block, which is "case 'form':".  That's why I like switch(), and 
disagree with Python's lack of it, but whatever.

Finally, if the user did have the correct data, and the "confirm" form 
with the hidden vars is submitted, it goes to

$_SERVER['PHP_SELF'] . "?action=commit"

and the data is actually inserted into the DB in the "commit" block of 
the switch statement.

The code looks like this:

switch($_GET['action']) {
        case 'commit':
                        // enter user's data into DB
                        break;
        case 'confirm':
                        // error check user input
                        // if valid, display a
                        // "<form action=\"" . $_SERVER['PHP_SELF'] . "?action=commit";
                        // if not valid, echo an error message
                        // and thendrop down to the next
                        // block of the switch() (case 'form')
                        // NO BREAK STATEMENT HERE
        case 'form':
                        // display a form with
                        // "<form action=\"" . $_SERVER['PHP_SELF'] . 
"?action=confirm";
                        break;
        default:
                        // you can also call this one "case 'intro'" if you want
                        // display the instructions for this page
}



HTH,

Erik




----

Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to