RE: [PHP] PHP_SELF
| From: | Ralph Guzman | Date: | Tue, 31 Jul 2001 07:49:50 +0000 |
| Subject: | RE: [PHP] PHP_SELF | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-60327@lists.php.net to get a copy of this message | ||
I personally think it is best to display a form error on the form itself,
rather than given them a blank page that shows an error, then have them
click a button or link to go back to the form. Here is somewhat a quick and
dirty example of how I go about forms and error checking. For this example I
am only checking for a required field, you can elaborate on this and check
to see if input for age is numerical, or whatever other type of
error-checking you may need to do:
<?
If($HTTP_POST_VARS){
// check required fields
if(!age ||
ame){
$formerror = "You did not fill in all required fields";
}
...
// if form passed all error checks continue processing
if(!$formerror){
// continue processessing...
....
}
}
?>
<? if(!$HTTP_POST_VARS || $formerror): ?>
<FORM ACTION="<? echo "$PHP_SELF"; ?>" METHOD="post">
<INPUT TYPE="text" NAME="name" VALUE="<? echo "$name";
?>">
<INPUT TYPE="text" NAME="age" VALUE="<? echo "$age";
?>">
<INPUT TYPE="submit" VALUE="Submit Form">
</FORM>
<? endif; ?>
Hope this helps.
-----Original Message-----
From: Gerard Samuel [mailto:trini0@optonline.net]
Sent: Monday, July 30, 2001 3:30 PM
To: PHP
Subject: [PHP] PHP_SELF
Im trying to introduce some logic into a form.I am unsing $PHP_SELF as
the target.
<form action=\"$PHP_SELF\" method=\"POST\"
type=\"multipart/form-data\">
I have a text area that the user inputs their age. What I want is that
if the field is blank, to stop the script and send the user back to fill
in their age. My problem now is that if I go to the blank application
form, The script interprets the form as being blank and spits out the
error. Ideal scenario, a blank form is presented to the user, and when
the form is submitted, do the logic check and act accordingly. Is it
possible using $PHP_SELF as the target, or do I have to use 2 files: a
form 'front end' with the php logic in the 'backend'??
if ($Age = " ") {
echo "Please go back and enter your age."; } exit();
Thanks
Gerard
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net