Hello,
I found a form that redisplays itself with error messages for fields not
filled in. I am trying to alter it so if the fields are filled in it will
redirect to another page...otherwise it will display itself with error
messages for fields not filled in.
The redirect works now, but I am having a problem with the script displaying
the form twice on the same page.
The ultimate goal of this script is to:
1) display a form
2)display the form again with error messages if fields are left blank
3)redirect to another page if fields are filled in
Here is the code......I apologize for the length.
<HEAD>
<TITLE>Feedback</TITLE>
</HEAD>
<BODY>
<?
$form_block = "
<FORM method=\"POST\" action=\"$PHP_SELF\">
<P>Your Name:<br>
<INPUT type=\"text\" name=\"sender_name\"
value=\"$sender_name\" size=30></p>
<P>Your E-Mail Address:<br>
<INPUT type=\"text\" name=\"sender_email\"
value=\"$sender_email\" size=30></p>
<P>Your Message:<br>
<textarea name=\"message\" cols=30
rows=5>$message</textarea>
</p>
<INPUT type=\"hidden\" name=\"op\" value=\"ds\">
<P><INPUT type=\"submit\" value=\"Send This Form\"></p>
</FORM>
";
if ($op == "ds"){
$send = "yes";
header("location: http://www.thickbook.com");
} else if ($op != "ds") {
// they need to see the form
echo "$form_block";
// check each required field and create an error message.
// if any of the required fields are blank, set $send to "no".
if ($sender_name == "") {
$name_err = "
<font color=red>Please enter your name!</font><br>
";
$send = "no";
}
if ($sender_email == "") {
$email_err = "
<font color=red>Please enter your e-mail address!</font><br>
";
$send = "no";
}
if ($message == "") {
$message_err = "
<font color=red>Please enter a message!</font><br>
";
$send = "no";
}
if ($send == "no") {
echo "$name_err";
echo "$email_err";
echo "$message_err";
echo "$form_block";
}
}
?>
</BODY>