Forum Moderators: coopster
# Default error_header
$error_header = "<p>The following errors occured, Pease be sure to include the missing fields before continuing</p><br>";
# error checking
if(!$_POST['name']) {
echo $error1 = '<p>Please Fill in the Name field</p>';
} /*check to make sure name is filled in, if not display error message on form as error1*/
if(!$_POST['email']) {
echo $error2 = '<p>Please fill in the email field</p>';
} /*check to make sure email is filled in, if not display error message on form as error3*/
if(!$_POST['suggestion']) {
echo
$error3 = '<p>Please fill in a suggestion</p>';
} /*check to make sure a suggestion is filled in, if not display error message on form as error3*/
if($error1 ¦¦ $error2 ¦¦ $error3) {
echo $error_header;
}
else {
header("Location: thankyou.php"); //error testing ended
}
}
?>
<?php
include ('./includes/header.inc.php');
?>
<div class="content"><center>
<table width="80%" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
/* this is the only place I want the initial error message insgted of on top of the page where the (if) statement is placing it*/
<td colspan="2" align="center"><? echo "<font color='red'>$error_header</font>";?><br><? echo "<font color='red'>$error1</font>";?><? echo "<font color='red'>$error2</font>";?><?echo "<font color='red'>$error3</font>";?></td>
</tr>
</table>
</center>
###############################################
Thanks, pat
To eliminate the error_header that appears on top, make this change:
Current version:
if($error1 ¦¦ $error2 ¦¦ $error3) { echo $error_header; <-- prints at the top } else { header("Location: thankyou.php"); } New version:
if(!$error1 &&!$error2 &&!$error3) { header("Location: thankyou.php"); } Just go to the thanks page if everything's okay, otherwise let the page print with your error variables displayed inside the cell.
Are you talking about a "clear" button to empty the contents of the form fields? If so, use
<input type="reset" value="Clear"> The "reset" buttons function is to reset the form to its default state.
if(!$error1 &&!$error2 &&!$error3) {
header("Location: thankyou.php"); //error testing ended
}
}\######################################
yet the missing fields minus the error_header still show up on the top right of the page above the pageheader. I guess the reset button does not work if i try to reset the page with the error messages on it. If i do it to the origninal page it clears it.
Thanks again
Pat
Just so I have it straight ... here's how I imagine your page lays out before the form is submitted:
(inactive) error message <table> start
(inactive) error message table first row (error_header)
(inactive) error message table second row (errors)
(inactive) error message </table> end
<form> start
form fields
form reset button
form submit button
</form> end
Here's how it looks if the form is submitted with missing info:
error message <table> start
error message table first row (error_header)
error message table second row (errors)
error message </table> end
<form> start
form fields
form reset button
form submit button
</form> end
Trying to picture it ...
Re: errors printing in the wrong place:
It looks like the table IS at the top, so that's where the errors will show up. Aside from that, if the errors aren't being displayed within the table's cell, it may be because of a miffed closing TD tag. Anything not in a <td> ... </td> will print above the table.
Re: reset button:
If the reset button is included within the <form> ... </form> tags, it will clear that particular form every time ... no PHP required.
Is it for sure between those two tags on the "oops" page display?
The only reason I have ever seen a reset button fail to rest a form is when it is not included between the form-start and form-end tags. Even a missing form-end tag can break it on some browsers.
Check the source of your page in the browser (a) before you fill out the form and (b) after you submit it without all of the info (so you can see the error messages). Check the second source output carefully to make certain that all opening and closing tags are being included where they should be, and that your error messages and reset button are between the proper tags.
Perhaps something is happening in header.inc.php?
At this point, it is probably more valuable for you to post snippets of the compiled page code (from the browser source) than to post snippets from the PHP code. For troubleshooting ...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang=en><head>
<title></title>
<link rel="stylesheet" type="text/css" href="./includes/bluegrass.css">
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head><body >
<div class="top">
<div class="left">
<a href="home.php">
Home</a></div>
<div class="right_of_left">
<a href="Contacts.php">
Contacts</a></div>
<div class="left2right">
<a href="comments.php">
Comments</a></div>
<div class="right">
<a href="sitemap.php">
Site-Map
</a></div>
</div>
<div class="content"><center>
<table width="80%" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td colspan="2" align="center"><font color='red'><p>The following errors occured, Pease be sure to include the missing fields before continuing</p><br></font></td>
</tr><--- the above error indicator, right place
</table>
</center>
#########################
Tell me when you want more you already have the main PHP code. The clear form is above the closing form tags