Re: PHP 4 session's probelm/design issue ?
| From: | php3 at developersdesk dot com | Date: | Thu, 07 Dec 2000 05:39:28 +0000 |
| Subject: | Re: PHP 4 session's probelm/design issue ? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-29059@lists.php.net to get a copy of this message | ||
Addressed to: "Chan Wai Wai" <chanww@globalsources.com>
php-general@lists.php.net
** Reply to note from "Chan Wai Wai" <chanww@globalsources.com> Thu, 7 Dec 2000
11:50:51 +0800
>
> Hi folks,
>
> Here is the issue I encountered using the session feature in PHP
> 4.02pl2 :
>
>
> I have a blank form allowing user to enter data. Upon submission, if
> user did not key in correctly, I direct the user to an error screen.
> The issue started here --> when the user clicks the "back" button,
> all of the previous entered data were gone.
>
> If I took out the session things, this won't happen. How could I
> solve this ? Can someone help, please ?
Don't use the back button!
If the user makes an error, re-paint the entry form, with all the
existing input filled in, and an error message telling what went wrong,
and how to fix it. If everything is correct update your database or
whatever, then redirect to the next page.
I think most entry forms should go back to themselves when accepted,
and use an outline like this:
---------------------------------------------------------
<?
if( 'Accept' == $Action ) { # Action is the name of the submit button.
# Accept is its value
# Accept button was hit...
$Message = '';
$Errors = 0;
# Validate User Input - Field 1
if( empty( $Field1 )) {
$Message .= 'Field 1 can not be blank<BR>\n';
$Errors ++;
}
if( 'Initial Value' == $Field1 ) {
$Message .= 'Field must be filled in!<BR>\n';
$Errors ++;
}
# Validate User Input - Field n ...
# Check for errors
if( 0 == $Errors ) {
# Update the database or whatever here
header( "Location: next_page" );
exit;
}
}
else # First time into page
# Get data from the database, or setup initial values
$Field1 = 'Initial Value';
}
?>
<HTML>
<HEAD>
<TITLE>My Form</TITLE>
</HEAD>
<BODY>
<FORM ACTION="<?=$PHP_SELF?>" Method="Post">
<H1>My Demo Form</H1>
<?=$Message?><BR>
Field 1: <INPUT Type="Text" Name="Field1"
Value="<?=$Field1?>"><BR>
<BR><BR>
<INPUT Type="Submit" Name="Action" Value="Accept">
</FORM>
</BODY>
</HTML>
---------------------------------------------------------
Rick Widmer
Internet Marketing Specialists
http://www.developersdesk.com