Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi, I'm new to PHP and i've found this script off another website which works great for me, but i would like to know how do i change it so that when a required field is left empty, and the user has to go back and refill it in, all the fields are not reset. For instance, so if someones typed a long message, then forget to put their email address in, when submitted, it is not cleared and they don't have to type the whole long message again. Any help would be much appreciated. thank you.Code: Select all
<?php
if (($_POST) and (!empty($_POST['name'])) and (!empty($_POST['email'])) and (!empty($_POST['message']))) {
if (get_magic_quotes_gpc()) {
foreach ($_POST as $key => $value) {
$temp = stripslashes($value);
$_POST[$key] = $temp;
}
}
$to = 'info@domain.com';
$subject = 'formsubject';
// message goes here
$message = "Full Name: " . $_POST['name'] . "\n";
$message .= "Email: " . $_POST['email'] . "\n";
$message .= "Telephone: " . $_POST['phone'] . "\n";
$message .= "Message: " . $_POST['message'] . "\n";
// headers go here
$headers = "From: " . $_POST['email'] . "\n";
$headers .= "Content-type: text/plain; charset=UTF-8";
//send mail
$sent = mail($to, $subject, $message, $headers);
$autorespond = mail($_POST['email'], "Form Auto Response.", "Thank you for contacting me, your message has been received and we will contact you shortly.", "From: Me <info@domain.com>");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Title</title>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Contact</h1>
<?php
if (isset($sent)) {
echo '<p><span class="thanks"><strong>Thank you</strong> for contacting us. Your message will be responded to as soon as possible.</span></p>';
}
else if ((empty($_POST['name'])) or (empty($_POST['email'])) or (empty($_POST['message']))) {
echo '<p>Please ensure you have filled out all the required fields</p>';
}
?>
<div id="form">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<legend>Personal information</legend>
<span class="formLabel"><label for="name">Full Name:</label><br /></span>
<input class="inputfield" type="text" id="name" name="name" size="30" />
<span class="formLabel"><label for="email">Email:</label><br /></span>
<input class="inputfield" type="text" id="email" name="email" size="30" />
<p><span class="formMessage"><label for="message">Message:</label><br /></span>
<textarea class="inputarea" id="message" name="message" rows="5" cols="30"></textarea></p>
</fieldset>
<p><input type="submit" class="inputsend" name="Submit" value="Send Form" /></p>
</form></div><!-- end #form -->
</body>
</html>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]