RE: [PHP] form validation
| From: | Ralph Guzman | Date: | Wed, 25 Oct 2000 02:58:26 +0000 |
| Subject: | RE: [PHP] form validation | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-21955@lists.php.net to get a copy of this message | ||
I think the best way to do this is to do the validation within the same form
page (domain.php). If you use header(); to redirect the user back the page,
you will loose all values of any of the other fields. this will be
frustating for the user. Here is an easy way to do it, quick and dirty, not
the most efficient but it should get you off to a good start. Try something
like this:
<?
if($action == "validate"):
if(!$first_name || !$last_name || !$address1 || !$address2 || !$phone ||
!$email || !$paymentmethod){
$error_msg = "You did not fill in all Required Fields";
}
endif;
?>
<? if(!$action || isset($error_msg)): ?>
<? if(isset($error_msg)): ?>
<H2><FONT COLOR="red"><? echo "$error_msg";
?></FONT><H2>
<? endif; ?>
<FORM ACTION="<? echo "$PHP_SELF?action=validate"; ?>"
METHOD="post">
<INPUT TYPE="text" NAME="$first_name" VALUE="<? echo
"$first_name"; ?>">
<? if(isset($error_msg) && !$first_name): ?><IMG SRC="error_img.gif"
BORDER="0"><? endif; ?>
<INPUT TYPE="text" NAME="$last_name" VALUE="<? echo
"$last_name"; ?>">
<? if(isset($error_msg) && !$last_name): ?><IMG SRC="error_img.gif"
BORDER="0"><? endif; ?>
...
...
<INPUT TYPE="submit" VALUE="Submit">
</FORM>
<? endif; ?>
<? if(isset($action) && !$error_msg):?>
<H2>Thank you for Submitting this Form. Below is your Info:</H2>
First Name: <? echo "$first_name"; ?><BR>
Last Name: <? echo "$last_name"; ?><BR>
...
...
<? endif; ?>
-----Original Message-----
From: "george" <@toye.php.net gmclachlan @btinternet.com
[mailto:nospam@netraiser.com]
Sent: Friday, October 20, 2000 7:09 AM
To: php-general@lists.php.net
Subject: [PHP] form validation
I have a form which when you type a domain name into it ,it searches a
database to see if that name is available,if it is it goes to a another form
which they must fill out with their name and address etc,which is then
mailed to me,i want to use php to validate the form but i 'm not too sure
how to.,basically i want to check if they have filled in the requried fields
and if not send them back to the page and place a graphic beside each of the
fields not correctly filled in ,on my confirmation page which lists all the
details they have supplied i have
if (($first_name == "") && ($last_name == "") && ($address1 ==
"") &&
($address2 == "")
&& ($town == "") && ($phone == "") && ($email ==
"") && ($paymentmethod ==
"")) {
header("Location: http://wisemonkeydesign.co.uk/domain.php");
exit;
but it doesnt work,
I hope someone can help me solve these 2 problems
Thanks in advance
George
--
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