form issue not sure how to reset variables passed to script
Posted: Wed Jul 01, 2009 5:18 am
Hello,
I am new to PHP but am here sitting in front of my machine at 3am going through various threads and looking at ways others have developed code. I have a little project and am not sure what is going on and have honestly tried to understand the logic before asking stupid questions.
Here it goes.
I have a simple HTML form that I am passing variables to a php script through the post method. The values are received just fine on the first pass. I have a couple If statements check to see if the name and email fields have some sort of value before proceeding.
Lets say I fill out the form in its entirety and submit it pursues and I get the expected email process to function. If I fail to fill in a value for one of the required fields it creates an out put page of say... "Check name field" so I use the back button and fill in the value then click submit and it thinks the value is not present. I have even had the IF statement push me to a new header page on my site and then navigate back to the form and still the same result.
Is this an issue with my form or the php script? I am not creating any specific cookie or defining a session instance.
Here is my code... any thing you can suggest or slap me silly with is appreciated.
HTML Form....
I am new to PHP but am here sitting in front of my machine at 3am going through various threads and looking at ways others have developed code. I have a little project and am not sure what is going on and have honestly tried to understand the logic before asking stupid questions.
Here it goes.
I have a simple HTML form that I am passing variables to a php script through the post method. The values are received just fine on the first pass. I have a couple If statements check to see if the name and email fields have some sort of value before proceeding.
Lets say I fill out the form in its entirety and submit it pursues and I get the expected email process to function. If I fail to fill in a value for one of the required fields it creates an out put page of say... "Check name field" so I use the back button and fill in the value then click submit and it thinks the value is not present. I have even had the IF statement push me to a new header page on my site and then navigate back to the form and still the same result.
Is this an issue with my form or the php script? I am not creating any specific cookie or defining a session instance.
Here is my code... any thing you can suggest or slap me silly with is appreciated.
HTML Form....
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>somewhere.com</title>
<link href="bg.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="container">
<div id="header">
<div id="nav">
<a href="index.html" class="navbutton">Home</a><a href="portfolio.html" class="navbutton">Portfolio</a><a href="contact.html" class="navbutton">Contact</a>
</div>
</div>
<div id="message">
<h1>Contact Information</h1>
<div id="mesnav">
<p><a href="contact.html" class="contactopts">Someone</a></p>
<p><a href="contact_local.html" class="contactopts">Local Shop</a></p>
<p class="selected">Appointment Request</p>
<p><a href="contact_sendexample.html" class="contactopts">Send Example</a></p>
</div>
</div>
<div id="minipg">
<form method="post" action="email.php" name="apptreq" id="apptreq" enctype="text/plain">
<h2>Appointment Request Form</h2>
<table>
<tr>
<td>Your Name:</td>
</tr>
<tr>
<td><input type="text" name="name" id="name" /></td>
</tr>
<tr>
<td>Email Address:</td>
</tr>
<tr>
<td><input type="text" name="from" id="from" /></td>
</tr>
</table>
<table>
<tr>
<td>Body Object:</td><td>Canvas Type:</td>
</tr>
<tr>
<td><input type="text" name="bodypart" id="bodypart" /></td><td><select name="skin" id="skin">
<option value="Select..." selected="selected">Please Select...</option>
<option value="Is it Gonna Hurt???">Is it Gonna Hurt???</option>
<option value="Wanna see my cute Tan?">Wanna see my cute Tan?</option>
<option value="I have Fair Skin">I have Fair Skin</option>
<option value="I am a tough SOB!">I am a tough SOB!</option>
<option value="Darker than you!">Darker than you!</option>
<option value="Who cares!">Who cares!</option>
</select></td>
</tr>
<tr>
<td>Size:</td>
</tr>
<tr>
<td><input type="text" name="size" id="size" /></td><td><input type="radio" name="color" value="black & White" id="black" /><label for="black">Black & White</label><input type="radio" name="color" value="Mixed Color" id="color" /><label for="color">Mixed Color</label></td>
</tr>
</table>
<table>
<tr>
<td>Description:</td>
</tr>
<tr>
<td><textarea cols="45" rows="4" name="description" id="description"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="submit" id="submit" value="Submit Request" class="button" /><input type="reset" value="Reset Form" class="button" /></td>
</tr>
</table>
<p>** Deposit may be required to hold appointment.</p>
</form>
</div>
<div id="footer">
<p><b>Copyright © - somewhere.com</b> - <em>Site coded by somewhere.com</em></p>
</div>
</div>
</body>
</html>
Code: Select all
PHP script....
<?php
//if(isset($_POST["name"])) $name=$_POST["name"];
//if(isset($_POST["from"])) $from=$_POST["from"];
$name=$_POST["name"];
$from=$_POST["from"];
$error="";
if($name == "") $error="<br /><br />"."*Please enter your name";
if($from == "") $error="<br />"."*Please enter your email"."<br /><br />";
if($error == ""){
//if($from == "") {echo "Looks like we need your email address please..." ;}
//else {
//if($name == "") {echo "Looks like we need your name please..." ;}
//else {
$headers = "From: $from";
$subject = "somewhere.com - New Appointment Request";
$to = "someone@somewhere.com";
$fields = array();
$fields{"name"} = "name";
$fields{"from"} = "from";
$fields{"bodypart"} = "bodypart";
$fields{"skin"} = "skin";
$fields{"size"} = "size";
$fields{"color"} = "color";
$fields{"description"} = "description";
$body = "You have a new appointment request from with the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_POST[$a]); }
$headers2 = "From: noreply@somewhere.com";
$subject2 = "somewhere.com - New Appointment Request";
$autoreply = "Thank you for your request.\n\nI should be able to review the information provided and get back to you shortly. In the event I do not respond within 48 hours please feel free to contact me directly. You can find my information in the same area you submited this request at http://www.somewhere.com\n\nIn the event you have received this message in error please contact the administrator at webmaster@somewhere.com\n\nThank you!\nSomeones Name";
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.somewhere.com/thankyou.html" );}
else
{echo "We encountered an error sending your mail, please notify webmaster@somewhere.com";}
}
Else{Echo "Sorry it appears you didn't fill in the following field(s)" .$error. "Please go back and verify before proceeding.";
}
?>