Hi all
I have a contact form which I set up and I am not sure how to make it can recall certain information if there is an error - so if the person fills in firstname but does not fill in emailaddress then when it shows the error it will remember the firstname. $_POST['firstname']?
contact.php
<?php
Header("Content-Type: image/png");
session_start();
if ($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=\"inc/contactmachine.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\" 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> ";
require ("inc/footer.inc.php");
}
?>
inc/contactmachine.php
<?php
session_start();
$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 == "") {
header("Location: ../contact.php?error=emailaddress&errornote=TRUE");
}
elseif ($qu == "") {
header("Location: ../contact.php?error=question&errornote=TRUE");
}
else {
mail ("emailaddress@email", "$fo", "$question", "from: $ea");
header("Location: ../contact.php?note=thankyouverymuch");
}
?>
I was thinking of combining this to one file but I think it might slow down the page.
Thanks a lot