Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Contact form data disappears

the mail() function

Moderators: macek, egami, gesf

Contact form data disappears

Postby jamescurl » Mon Jan 14, 2013 2:30 am

Hi,
I'm a bit stuck with my contact form code. When a user fills out the form and they get it wrong or miss some information an error appears and the data that they have entered disappears. How do I get it to keep the existing data that they have entered? I have the following:-

<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Kibblewhite Gardens</title>
<link href="favicon.ico" type="image/x-icon" rel="icon" />
<link href="favicon.ico" type="image/x-icon" rel="shortcut icon" />

<link href="kibblestyle.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="kibblestyle-ie.css" />
<![endif]-->


<link href="css/lightbox.css" rel="stylesheet" />
</head>

<body>
<?php

if (isset($_POST['submit'])) {
$error = "";

if (!empty($_POST['Name'])) {
$name = $_POST['Name'];
} else {
$error .= "You didn't type in your name. <br />";
}

if (!empty($_POST['Email'])) {
$email = $_POST['Email'];
if (!preg_match("/^[_a-z0-9]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email)){
$error .= "The e-mail address you entered is not valid. <br/>";
}
} else {
$error .= "You didn't type in an e-mail address. <br />";
}

if (!empty($_POST['Message'])) {
$message = $_POST['Message'];
} else {
$error .= "You didn't type in a message. <br />";
}

if (!empty($_POST['Telephone'])) {
$telephone= $_POST['Telephone'];
}

if(($_POST['code']) == $_SESSION['code']) {
$code = $_POST['code'];
} else {
$error .= "The captcha code you entered does not match. Please try again. <br />";
}

if (empty($error)) {
$from = 'From: ' . $name . ' <' . $email . '>';
$to = "info@jamescurl.co.uk";
$subject = "Message from Kibblewhite Gardens website";
$content = " From: ".$name . "\n Phone number: " . $telephone . "\n Message: " . $message;
$success = "<h3>Thank you! Your message has been sent!</h3>";
mail($to,$subject,$content,$from);
}
}
?>

<p>&nbsp;</p>
<table align="center" width="1090" border="0" >
<tr>
<td valign="top">
<div class="Contactpage-BG">
<table border="0" align="left" width="100%">

<tr>
<td>


<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div class="slogan">Quality garden design and landscaping since 1963</div></td>
<td>
<div class="menubuttons">
<div class="menubuttons-home"><div class="Boxmenubutton"></div><a href="index.php">Home</a></div>
<div class="menubuttons-services"><div class="Boxmenubutton"></div><a href="services.php">services</a></div>
<div class="menubuttons-testimonials"><div class="Boxmenubutton"></div><a href="testimonials.php">testimonials</a></div>
<div class="menubuttons-contact"><div class="Boxmenubutton"></div><a href="contact.php"><b>CONTACT</b></a></div>
<div class="blackline-contact"></div>
</div>
</td>
</tr>
</table>

</td>

</tr>
<tr>
<td align="left">
<div class="Testimonial">
<div class="Contact-BG">

<div class="Contact-Midleft">



</div>
<div class="Contact-text">
<p class="Contact-text"><i> *Compulsory Fields</i> </p>
</div>


<form method="post" action="" >
<table width="600" height="531" border="0" cellpadding="0">
<tr>
<td width="111" height="28" class="Contact-text"><div class="Contactboxes-name-label">*Name:</div></td>
<td colspan="2">
<input name="Name" type="text" class="Contactboxes-name" id="Name" value="<?php echo $_POST['name']; ?>"/>
</td>
</tr>
<tr>
<td height="28" class="Contact-text"><div class="Contactboxes-email-label">*Email:</div></td>
<td colspan="2"><input name="Email" type="text" size="60" class="Contactboxes-email" id="Email" value="<?php echo $_POST['email']; ?>"/></td>
</tr>
<tr>
<td height="28" class="Contact-text"><div class="Contactboxes-telephone-label"> Telephone:</div></td>
<td colspan="2"><input name="Telephone" type="text" class="Contactboxes-telephone" id="Telephone" value="<?php echo $_POST['telephone']; ?>"/></td>
</tr>
<tr>
<td height="139" valign="top" class="Contact-text"><div class="Contactboxes-message-label">*Message:</div></td>
<td colspan="2"><textarea name="Message" cols="56" rows="11" class="Contacttextarea" id="Message"><?php echo $_POST['message']; ?></textarea></td>
</tr>
<tr>
<td valign="top" class="Contact-text"><div class="Contactboxes-spam-label">*Anti-SpamBot Code:</div></td>
<td colspan="2" valign="top"><div class="Contactboxes-spam">Please enter the numbers you see in this image<br />
into the box below</div></td>
</tr>
<tr>
<td height="51">&nbsp;</td>
<td width="209" valign="top"><div class="Captchaimagebox"><label><img src="captcha.php"></label></div></td>
<td width="252" rowspan="3" valign="top">
<?php
if (!empty($error)) {
echo '<p class="error"><font color="#FF0000"><strong>Your message was NOT sent</strong></font><br/>' . $error . '</p>';
} elseif (!empty($success)) {
echo $success;
}
?>
</td>
</tr>
<tr>
<td height="48">&nbsp;</td>
<td valign="top"><input name="code" type="text" class="Captchabox"></td>
</tr>
<tr>
<td height="65">&nbsp;</td>
<td><input type="submit" class="Contact-Send" name="submit" value="" /></td>
</tr>
<tr>
<td height="50">&nbsp;</td>
<td height="50" colspan="2"><b>Kibblewhite Gardens ltd</b><br />
<div class="Contact-address">The Oast, Tanyard Farm, Sandhurst, Cranbrook, Kent TN18 5JY</div><br />
<div class="Contact-telephone">01580 850394</div></td>
</tr>
</table>
<p>
<div class="contactfields">
<label for="Name"></label></div></p>
</form>


</div>
<div class="Contact-Midright"></div>
</div>



</td>

</tr>

</table>


</div>
</td>
</tr>
</table>
<div class="Footer">
<div class="websiteby">Special thanks to Prof. Rosner &amp; A. Hickmott&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Photography by A. Gurr</div>
<div class="copyright">&copy; Copyright Kibblewhite Gardens</div>
</div>
</body>
</html>
jamescurl
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Jan 14, 2013 1:43 am

Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron