hey guys ive run into a problem which is probably a simple fix but i cant figure it out, I have more form and everything is working validation wise except for 2 things, when i put anything in the email section and leave the rest blank it shows me the error message but it also sends the form, and when i put anything in my text area it saves the value and prints it back after errors but for some reason it also puts the text area value in the phone section???
any help with this would be awesome thanks in advanced
<?php
$errormsg = ""; //Initialize errors
//If form was submitted
if ($_POST['submitted']==1) {
//Do something
if ($_POST[name]){
$name = $_POST[name]; //If name was entered
}
else{
$errormsg = "Please enter your Name";
}
if ($_POST[email]){
$email = $_POST[email]; //If email was entered
}
else{
if ($errormsg){ //If there is already an error, add next error
$errormsg = $errormsg . " & Email";
}else{
$errormsg = "Please enter your Email";
}
}
if ($_POST[phone]){
$phone = $_POST[phone]; //If phone was entered
}
else{
if ($errormsg){ //If there is already an error, add next error
$errormsg = $errormsg . " & Phone Number";
}else{
$errormsg = "Please enter your phone number";
}
}
if ($_POST[details]){
$phone = $_POST[details]; //If phone was entered
}
else{
if ($errormsg){ //If there is already an error, add next error
$errormsg = $errormsg . " & A brief project description";
}else{
$errormsg = "Please enter a brief project description";
}
}
}
if ($errormsg){ //If any errors display them
echo "$errormsg";
}
if ($_POST["email"]<>'') {
$ToEmail .= 'me@brendanperkins.com';
$EmailSubject .= 'Quote Form';
$mailheader .= "From: ".$_POST["name"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY .= "Name/Company: ".$_POST["name"]."<br />";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br />";
$MESSAGE_BODY .= "Phone: ".$_POST["phone"]."<br />";
$MESSAGE_BODY .= "Time: ".$_POST["call_option"]."<br />";
$MESSAGE_BODY .= "Development for: ".$_POST["development_for"]."<br /><br />";
$MESSAGE_BODY .= "Project Details:<br /><br /> ".nl2br($_POST["details"])."<br />";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
if ($name != '' && $email != '' && $phone != '' && $details != '' )
?>
<div id="formmessage">
<p>Thank you for your submission. We are now thinking of the best possible solution for your project and will be back to you in the next 1 to 2 working days. If this is urgent contact info@designpilotonline.com or call us at 1 416 538 3003.
-Design Pilot</p>
<?php
} else {
?>
<form action="testphp.php" method="post" id="quote-form">
<ul>
<li><label for="name">Name/Company</label><input name="name" type="text" id="name" size="32"
value="<?php echo "$name"; ?>"/></li>
<li><label for="email">Your E-mail</label><input name="email" type="text" id="email" size="32"
value="<?php echo "$email"; ?>"/></li>
<li><label for="phone">Phone</label><input name="phone" type="text" id="phone" size="32"
value="<?php echo "$phone"; ?>"/></li>
<li><label><span>9am -5pm:
<input type="checkbox" value="9am-5pm" size="35" name="call_option" />
and/or 5pm -9pm:</span>
<input type="checkbox" value="5pm-9pm" size="35" name="call_option2" /></label></li>
<li><label for="development_for">Design/Development for:</label>
<select name="development_for" id="development_for">
<option value="Print">Print</option>
<option value="Logo_Branding">Logo/Branding</option>
<option value="Web">Web</option>
<option value="Campaign">Campaign</option>
<option value="Other">Other</option>
</select></li>
<li><label for="details">Explain your project</label><br />
<textarea name="details" cols="45" rows="10" id="details" ><?php echo $_POST['details']?></textarea></li>
<li><input type="hidden" name="submitted" value="1" /></li>
<li><input type="submit" name="Submit" value="Send" onclick="javascript:document.forms[0].submit"/></li>
</ul>
<?php
};
?>
</form>
php validation problem
Moderator: General Moderators
Re: php validation problem
I figured out why it was posting to phone as well and thats taken care of but i still cant seem to figure out why whenever anything is in the email section and the rest is blank why it sends the form anyway while still showing me what errors have happened
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: php validation problem
Describing a problem and posting your entire script, as you may have noticed, doesn't get you many replies. Firstly, put your script in
Code: Select all
tags. Secondly, be specific about what and where the problem is.
Take a deep breath and try again. :p