Xelex Posted November 19, 2008 Share Posted November 19, 2008 Ok, so I've got a form to work thanks to the help of this community, and I've noticed a few minor problems... First off, I noticed that if a person doesn't fill in all the forms, it will fail to submit. Why is that? And finally, I have a comment text area, and if it exceeds a certain amount of characters, it will give you a success screen even though the email is never really sent. Is there a reason why? And if so, is it due to the script or the client? EDIT: Disregard; \n is an amazing thing. But how do I allow my script to omit fields if they enter nothing in there? As in, instead of failing to process if they leave a field blank, to go ahead and process anyways? Here's the script: <?php if ($_POST["email"]<>'') { $ToEmail = '**********@hotmail.com' . ', '; $ToEmail .= '******@gmail.com'; $EmailSubject = 'Site contact form '; $mailheader = "From: ".$_POST["email"]."\r\n"; $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $MESSAGE_BODY = "\nFirst Name: ".$_POST["name"]."<br>"; $MESSAGE_BODY .= "\nLast Name: ".$_POST["name2"]."<br>"; $MESSAGE_BODY .= "\nAffilliation/Convention: ".$_POST["name3"]."<br>"; $MESSAGE_BODY .= "\nHome Phone Number: ".$_POST["name4"]."<br>"; $MESSAGE_BODY .= "\nCell Phone Number: ".$_POST["name5"]."<br>"; $MESSAGE_BODY .= "\nWork Phone Number: ".$_POST["name6"]."<br>"; $MESSAGE_BODY .= "\nDates for Rental: ".$_POST["name7"]."<br>"; $MESSAGE_BODY .= "\nType of Equipment: ".$_POST["FieldData"]."<br>"; $MESSAGE_BODY .= "\nEmail Address: ".$_POST["email"]."<br>"; $MESSAGE_BODY .= "\nAdditional Comments: ".nl2br($_POST["comment"])."<br>"; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure. Again!"); ?> <b>Your message was sent to one of our representatives, and will be reviewed. We look forward to contacting you in the near future, thank you.</b> <?php } else { ?> <form action="contact_us_test.php" method="post"> <table width="400" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="29%" class="bodytext">First name:</td> <td width="71%"><input name="name" type="text" id="name" size="32"></td> </tr> <tr> <td width="29%" class="bodytext">Last name:</td> <td width="71%"><input name="name2" type="text" id="name" size="32"></td> </tr> <td width="29%" class="bodytext">Affiliation/Convention:</td> <td width="71%"><input name="name3" type="text" id="name" size="32"></td> </tr> <tr> <td class="bodytext">Customer Home Number:</td> <td><input name="name4" type="text" id="name" size="32"></td> </tr> <tr> <td width="29%" class="bodytext">Customer Cell Number:</td> <td width="71%"><input name="name5" type="text" id="name" size="32"></td> </tr> <tr> <td width="29%" class="bodytext">Customer Work Number:</td> <td width="71%"><input name="name6" type="text" id="name" size="32"></td> </tr> <tr> <td width="29%" class="bodytext">Dates for Rental:</td> <td width="71%"><input name="name7" type="text" id="name" size="32"></td> </tr> <tr> <td class="bodytext">Email address:</td> <td><input name="email" type="text" id="email" size="32"></td> </tr> <tr> <td nowrap="nowrap"><span class="style19"><font face="Verdana" color="#000000">Type of Equipment Needed</font></span></td> <td><select name="FieldData"> <option value="Power Wheelchair">Power Wheelchair</option> <option value="Power Scooter">Power Scooter</option> <option value="Other">Other</option> </select> </td> </tr> <tr> <td class="bodytext">Comment:</td> <td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td> </tr> <tr> <td class="bodytext"> </td> <td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> <?php }; ?> Link to comment https://forums.phpfreaks.com/topic/133285-php-forms/ Share on other sites More sharing options...
redarrow Posted November 19, 2008 Share Posted November 19, 2008 Try it this way to send a email and show the form always with no valadation condition's <?php if (isset($_POST["email"])) { $ToEmail = '**********@hotmail.com' . ', '; $ToEmail .= '******@gmail.com'; $EmailSubject = 'Site contact form '; $mailheader = "From: ".$_POST["email"]."\r\n"; $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $MESSAGE_BODY = "\nFirst Name: ".$_POST["name"]."<br>"; $MESSAGE_BODY .= "\nLast Name: ".$_POST["name2"]."<br>"; $MESSAGE_BODY .= "\nAffilliation/Convention: ".$_POST["name3"]."<br>"; $MESSAGE_BODY .= "\nHome Phone Number: ".$_POST["name4"]."<br>"; $MESSAGE_BODY .= "\nCell Phone Number: ".$_POST["name5"]."<br>"; $MESSAGE_BODY .= "\nWork Phone Number: ".$_POST["name6"]."<br>"; $MESSAGE_BODY .= "\nDates for Rental: ".$_POST["name7"]."<br>"; $MESSAGE_BODY .= "\nType of Equipment: ".$_POST["FieldData"]."<br>"; $MESSAGE_BODY .= "\nEmail Address: ".$_POST["email"]."<br>"; $MESSAGE_BODY .= "\nAdditional Comments: ".nl2br($_POST["comment"])."<br>"; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure. Again!"); ?> <b>$name Your message was sent to one of our representatives, and will be reviewed. We look forward to contacting on you on $email in the near future, thank you.</b> <form action="contact_us_test.php" method="post"> <table width="400" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="29%" class="bodytext">First name:</td> <td width="71%"><input name="name" type="text" id="name" size="32"></td> </tr> <tr> <td width="29%" class="bodytext">Last name:</td> <td width="71%"><input name="name2" type="text" id="name" size="32"></td> </tr> <td width="29%" class="bodytext">Affiliation/Convention:</td> <td width="71%"><input name="name3" type="text" id="name" size="32"></td> </tr> <tr> <td class="bodytext">Customer Home Number:</td> <td><input name="name4" type="text" id="name" size="32"></td> </tr> <tr> <td width="29%" class="bodytext">Customer Cell Number:</td> <td width="71%"><input name="name5" type="text" id="name" size="32"></td> </tr> <tr> <td width="29%" class="bodytext">Customer Work Number:</td> <td width="71%"><input name="name6" type="text" id="name" size="32"></td> </tr> <tr> <td width="29%" class="bodytext">Dates for Rental:</td> <td width="71%"><input name="name7" type="text" id="name" size="32"></td> </tr> <tr> <td class="bodytext">Email address:</td> <td><input name="email" type="text" id="email" size="32"></td> </tr> <tr> <td nowrap="nowrap"><span class="style19"><font face="Verdana" color="#000000">Type of Equipment Needed</font></span></td> <td><select name="FieldData"> <option value="Power Wheelchair">Power Wheelchair</option> <option value="Power Scooter">Power Scooter</option> <option value="Other">Other</option> </select> </td> </tr> <tr> <td class="bodytext">Comment:</td> <td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td> </tr> <tr> <td class="bodytext"> </td> <td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> <?php }; ?> Link to comment https://forums.phpfreaks.com/topic/133285-php-forms/#findComment-693237 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.