Forum Moderators: coopster
I am having trouble with my contact form not submitting - I would like it to error check and highlight the fields not filled in (keeping the ones that were filled in). I tried it on firefox once and it came up with a message saying that the png had an error in it - could be a local setting.
Here it is:
<?php
Header("Content-Type: image/png");
session_start();
if (isset($_POST[submit])) {
$fo = $_POST['for'];
$fn = $_POST['firstname'];
$ln = $_POST['lastname'];
$ea = $_POST['emailaddress'];
$qu = $_POST['question'];
$random = trim($random);
if (!$new_string == $random){
header("Location: contact.php?error=verification&errornote=TRUE");
}
elseif ($fn == "") {
header("Location: contact.php?error=firstname&errornote=TRUE");
}
elseif (($ea == "") ¦¦ (!eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $ea))) {
header("Location: contact.php?error=emailaddress&errornote=TRUE");
}
elseif ($qu == "") {
header("Location: contact.php?error=question&errornote=TRUE");
}
else {
mail ("email@myemail.com", "$fo", "$question", "from: $ea");
header("Location: contact.php?note=thankyouverymuch");
}
}
elseif ($note==thankyouverymuch)
{
$page="contact"; require ("inc/top.inc.php");
echo "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"content\">";
echo "<tr>";
echo "<td valign=\"top\">";
echo "<h1>Thank you!</h1>";
echo "<br />";
echo "<h3>We will be in contact with you as soon as possible</h3>";
echo "</div>";
echo "</td>";
echo "</tr> ";
echo "</table>";
require ("inc/footer.inc.php");
}
else {
$page="contact"; require ("inc/top.inc.php");
$new_string;
session_register('new_string');
$im = ImageCreate(200, 40);
$white = ImageColorAllocate($im, 255, 255, 255);
$black = ImageColorAllocate($im, 0, 0, 0);
srand((double)microtime()*1000000);
$string = md5(rand(0,9999));
$new_string = substr($string, 17, 5);
ImageFill($im, 0, 0, $white);
ImageString($im, 4, 45, 19, $new_string, $black);
/* Directory inc/c/ is CHMODDed to 777 */
ImagePNG($im, "inc/c/verify.png");
ImageDestroy($im);
echo "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"content\">";
echo "<tr>";
echo "<td valign=\"top\">";
echo "<h1>Contact us</h1>";
echo "<br />All fields maked * are required";
if ($errornote=='TRUE') {
echo "<br /><br />Please fill in all fields marked <span style=\"color: red;\">RED</span>";
}
echo "<div id=\"contactform\">";
echo " <form action=\"contact.php\" method=post>";
echo "<label for=\"for\">For: *</label>";
echo "<select name=\"for\">";
echo "<option>Business";
echo "<option>Help";
echo "<option>Personal";
echo "</select><br />";
echo "<label for=\"firstname\">First name: *</label>";
echo "<input type=\"text\"";
echo "name=\"firstname\"";
if ($error==firstname) {
echo " style=\"border: 1px solid red;\"><br />";
}
else {
echo "><br />";
}
echo "<label for=\"lastname\">Last name:</label>";
echo "<input type=\"text\" name=\"lastname\"";
if ($error==lastname) {
echo " style=\"border: 1px solid red;\"><br />";
}
else {
echo "><br />";
}
echo "<label for=\"emailaddress\">Email address: *</label>";
echo "<input type=\"text\" name=\"emailaddress\"";
if ($error==emailaddress) {
echo " style=\"border: 1px solid red;\"><br />";
}
else {
echo "><br />";
}
echo "<label for=\"question\">";
if ($error==question) {
echo "<span style=\"color: red;\">Question *</span></label>";
}
else {
echo "Question</label>";
}
echo "<textarea name=\"question\" rows=\"10\" cols=\"10\"></textarea><br />";
echo "<img src=\"inc/c/verify.png\">";
echo "<br />";
echo "Please type the contents of the image *";
echo "<br /><br />";
echo "<input name=\"random\" type=\"text\" value=\"\"";
if ($error==verification) {
echo "style=\"border: 1px solid red;\">";
}
else {
echo ">";
}
echo "<br /><br />";
echo "<input type=\"submit\" value=\"Send\">";
echo "</form>";
echo "</div> ";
echo "</td> ";
echo "</tr> ";
echo "</table> ";
echo "<h3>We respect your privacy and we will never sell your email address to any third party. The information submitted in this form will be sent directly to Erin Wheelan, managing director of Eyelights Ltd.</h3>";
require ("inc/footer.inc.php");
}
?>
It still does not appear to submit.
<?php
session_start();
if (isset($_POST[submit])) {
$fo = $_POST['for'];
$fn = $_POST['firstname'];
$ln = $_POST['lastname'];
$ea = $_POST['emailaddress'];
$qu = $_POST['question'];
$random = trim($random);
if (!$new_string == $random){
header("Location: contact.php?error=verification&errornote=TRUE");
}
elseif ($fn == "") {
header("Location: contact.php?error=firstname&errornote=TRUE");
}
elseif (($ea == "") ¦¦ (!eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $ea))) {
header("Location: contact.php?error=emailaddress&errornote=TRUE");
}
elseif ($qu == "") {
header("Location: contact.php?error=question&errornote=TRUE");
}
else {
mail ("email@myemail.com", "$fo", "$question", "from: $ea");
header("Location: contact.php?note=thankyouverymuch");
}
}
elseif ($note==thankyouverymuch)
{
$page="contact"; require ("inc/top.inc.php");
echo "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"content\">";
echo "<tr>";
echo "<td valign=\"top\">";
echo "<h1>Thank you!</h1>";
echo "<br />";
echo "<h3>We will be in contact with you as soon as possible</h3>";
echo "</div>";
echo "</td>";
echo "</tr> ";
echo "</table>";
require ("inc/footer.inc.php");
}
else {
$page="contact"; require ("inc/top.inc.php");
$new_string;
session_register('new_string');
$im = ImageCreate(200, 40);
$white = ImageColorAllocate($im, 255, 255, 255);
$black = ImageColorAllocate($im, 0, 0, 0);
srand((double)microtime()*1000000);
$string = md5(rand(0,9999));
$new_string = substr($string, 17, 5);
ImageFill($im, 0, 0, $white);
ImageString($im, 4, 45, 19, $new_string, $black);
/* Directory inc/c/ is CHMODDed to 777 */
ImagePNG($im, "inc/c/verify.png");
ImageDestroy($im);
echo "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"content\">";
echo "<tr>";
echo "<td valign=\"top\">";
echo "<h1>Contact us</h1>";
echo "<br />All fields maked * are required";
if ($errornote=='TRUE') {
echo "<br /><br />Please fill in all fields marked <span style=\"color: red;\">RED</span>";
}
echo "<div id=\"contactform\">";
echo " <form action=\"contact.php\" method=post>";
echo "<label for=\"for\">For: *</label>";
echo "<select name=\"for\">";
echo "<option>Business";
echo "<option>Help";
echo "<option>Personal";
echo "</select><br />";
echo "<label for=\"firstname\">First name: *</label>";
echo "<input type=\"text\"";
echo "name=\"firstname\"";
if ($error==firstname) {
echo " style=\"border: 1px solid red;\"><br />";
}
else {
echo "><br />";
}
echo "<label for=\"lastname\">Last name:</label>";
echo "<input type=\"text\" name=\"lastname\"";
if ($error==lastname) {
echo " style=\"border: 1px solid red;\"><br />";
}
else {
echo "><br />";
}
echo "<label for=\"emailaddress\">Email address: *</label>";
echo "<input type=\"text\" name=\"emailaddress\"";
if ($error==emailaddress) {
echo " style=\"border: 1px solid red;\"><br />";
}
else {
echo "><br />";
}
echo "<label for=\"question\">";
if ($error==question) {
echo "<span style=\"color: red;\">Question *</span></label>";
}
else {
echo "Question</label>";
}
echo "<textarea name=\"question\" rows=\"10\" cols=\"10\"></textarea><br />";
echo "<img src=\"inc/c/verify.png\">";
echo "<br />";
echo "Please type the contents of the image *";
echo "<br /><br />";
echo "<input name=\"random\" type=\"text\" value=\"\"";
if ($error==verification) {
echo "style=\"border: 1px solid red;\">";
}
else {
echo ">";
}
echo "<br /><br />";
echo "<input type=\"submit\" value=\"Send\">";
echo "</form>";
echo "</div> ";
echo "</td> ";
echo "</tr> ";
echo "</table> ";
echo "<h3>We respect your privacy and we will never sell your email address to any third party. The information submitted in this form will be sent directly to person.</h3>";
require ("inc/footer.inc.php");
}
?>
No that is not the issue - the issue is that the field is not filled in when they have to fix an error.
Say "firstname" and "email address" are required fields and I fill in firstname only. I am shown an error message that shows I must fill in the email address as well. The firstname that I entered is remembered so I don't have to fill it in again.
Hence the reason why I have the value=\"fn\" so that it will remember the fields I filled in correctly.
The source code should reflect this.
I realize this but what I am asking is if the value is showing in the source from the browser and possibly misformatted html so that it isn't in the field
if the value doesn't show at all then the issue is with assigning the value to $fn
I am just offering a way to diagnose your issue
Thanks
[edited by: jatar_k at 2:21 am (utc) on Oct. 7, 2005]
[edit reason] no urls thanks [/edit]
$fn = $_POST['firstname'];
echo '<p>POST[firstname]: ', $_POST['firstname'];
echo '<p>fn: ', $fn;
echo "<label for=\"firstname\">First name: *</label>";
echo "<input type=\"text\" value=\"$fn\" name=\"firstname\"";
if ($error==firstname) {
and when I pushed "submit" it didn't show the firstname.
echo "<p>\$_POST['firstname']: $_POST['firstname']</p>";
works:
echo "$_POST['firstname']";
echo "$_POST[ 'firstname' ]";
I have this:
echo "<label for=\"firstname\">First name: *</label>";
echo "<input type=\"text\" value=";
echo "$_POST['firstname']";
echo " name=\"firstname\"";
if ($error==firstname) {
And get:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in file.php on line 123
works:
echo "$atozArray['fixedstringorvariable']";
echo "$_atozArray['fixedstringorvariable']";