Jezthomp Posted February 6, 2007 Share Posted February 6, 2007 Recently i have noticed that a form template i have been using is not checking whether certain fields are not filled in and just posting the form regardless. <?php ini_set("sendmail_from", "mailserver@*******.co.uk"); if ($_POST["formName"] == "contactForm") { if (($_POST["name"] == "") OR ($_POST["email"] == "") OR ($_POST["telNum"] == "")) { print "<br>You have not given us all the information we need to process the form.<br>"; print "Please use the browser back and/or refresh button to go back and edit the form."; }else{ $recipient = "Enquiries <[email protected]>"; $subject = "Website Enquiry Form"; $name = $_POST["name"]; $telNum = $_POST["telNum"]; $email = $_POST["email"]; $website = $_POST["website"]; $comments = $_POST["comments"]; $message = "WEBSITE CONTACT FORM: ____________________________________________ Contact Info: Name: $name E-Mail Address: $email Contact No: $telNum There Website: $website ____________________________________________ Comments: Comments: $comments "; $extra = "From: $name <$email>"; mail ($recipient, $subject, $message, $extra); print "Many Thanks $name! for contacting us, we shall get back to you as soon as possible..."; } } else { ?> <form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post" name="contactForm"> <fieldset> <legend>Enquiry Form </legend> <div class="fieldContact"> <label for="name">Name: <span class="required" title="This field is required.">*</span></label> <input class="text" id="name" maxlength="64" name="name" size="24" title="Enter name here" value="Enter name here"onfocus="if (this.value == this.defaultValue) this.value = ''" onblur="if (!this.value) this.value=this.defaultValue" type="text"/> </div> <div class="fieldContact"> <label for="email">Email Address: <span class="required" title="This field is required.">*</span></label> <input class="text" id="email" name="email" size="32" title="Enter email address here" value="Enter email address here" onfocus="if (this.value == this.defaultValue) this.value = ''" onblur="if (!this.value) this.value=this.defaultValue"type="text"/> </div> <div class="fieldContact"> <label for="telNum">Tel No:<span class="required" title="This field is required.">*</span></label> <input name="telNum" class="text" id="telNum" title="Enter telephone number here" value="Enter telephone number here"onfocus="if (this.value == this.defaultValue) this.value = ''" onblur="if (!this.value) this.value=this.defaultValue" size="32" type="text"/> </div> <div class="fieldContact"> <label for="comments"><span>Comments:</span></label> <textarea name="comments" cols="25" rows="5" class="text" id="comments"></textarea> </div> </fieldset> <div><input name="Submit" type="submit" class="submit" value="Submit" /><input name="formName" type="hidden" id="formName" value="contactForm" /></div> </form> <?php } ?> Is suddenly not working when it used too This is an older form i used and it works in regard to checking the fields, the only difference is the one that doesnt work is a css form. <?php ini_set("sendmail_from", "mailserver@********.net"); if ($_POST["Submit"]) { if ((!$_POST["name"]) OR (!$_POST["telNum"]) OR (!$_POST["email"])) { print "<br>You have not given us all the information we need to process the form.<br>"; print "Please use the browser back and/or refresh button to go back and edit the form."; }else{ $recipient = "Enquiries <enquiries@*******.net>"; $subject = "Website Enquiry Form"; $name = $_POST["name"]; $company = $_POST["company"]; $telNum = $_POST["telNum"]; $email = $_POST["email"]; $message = $_POST["message"]; $message = "WEBSITE CONTACT FORM: ____________________________________________ PERSONAL INFO: Name: $name Company: $company Contact No: $telNum E-Mail Address: $email ____________________________________________ MESSAGE: Message: $message "; $extra = "From: $name <$email>"; mail ($recipient, $subject, $message, $extra); print "Many Thanks $name! for contacting us, we shall get back to you as soon as possible..."; } } else { ?><form action="http://www.***********.net/contact.php" method="post" name="form1"> <table width="100%" border="0" cellspacing="5" cellpadding="0"> <tr> <td width="61%" class="formTitles">Name:</td> </tr> <tr> <td><input name="name" type="text" class="formInformation" id="name" size="45" /></td> </tr> <tr> <td class="formTitles">Company:</td> </tr> <tr> <td><input name="company" type="text" class="formInformation" id="company" size="45" /></td> </tr> <tr> <td class="formTitles">Contact No: </td> </tr> <tr> <td><input name="telNum" type="text" class="formInformation" id="telNum" size="45" /></td> </tr> <tr> <td class="formTitles">Email:</td> </tr> <tr> <td><input name="email" type="text" class="formInformation" id="email" size="45" /></td> </tr> </table> <br /> <table width="100%" border="0" cellspacing="5" cellpadding="0"> <tr> <td class="formTitles">What would you like to know? </td> </tr> <tr> <td><textarea name="message" cols="45" rows="5" class="formInformation" id="message"></textarea></td> </tr> <tr> <td><input name="Submit" type="submit" class="submit" value="Submit" /></td> </tr></table> </form> <?php } ?> I'm no php wizard and a friend of mine did it on this form for me, so i have no idea why its doing it, the form is sending fine just whether the fields are filled in or not. I'm worrying this could leave it open to spam attacks anything i can add to to help that as well? Many thanks for any help, i'm sure i am being blind or something. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/37295-form-sending-whether-fields-filled-or-not/ Share on other sites More sharing options...
RobinTibbs Posted February 6, 2007 Share Posted February 6, 2007 i aint to php genius either butttt i think its because you are using OR and maybe the brackets around the $_POST things could be affecing it. rather than OR, try | since that is the correct comparison operator to use, i think hope that helps so (($_POST["name"] == "") OR ($_POST["email"] == "") OR ($_POST["telNum"] == "")) would become ($_POST["name"] == "" | $_POST["email"] == "" | $_POST["telNum"] == "") Quote Link to comment https://forums.phpfreaks.com/topic/37295-form-sending-whether-fields-filled-or-not/#findComment-178375 Share on other sites More sharing options...
Balmung-San Posted February 6, 2007 Share Posted February 6, 2007 Actually, || would be the "or" that RobinTibbs means, however OR is also a valid logcal operator. As for the main subject matter, I wouldn't use == for string comparisons, instead I would use strcmp: if((strcmp($_POST['whatever'], "") == 0) OR ... Quote Link to comment https://forums.phpfreaks.com/topic/37295-form-sending-whether-fields-filled-or-not/#findComment-178380 Share on other sites More sharing options...
Jezthomp Posted February 6, 2007 Author Share Posted February 6, 2007 That doesn't work Robin Thankyou anyway. Quote Link to comment https://forums.phpfreaks.com/topic/37295-form-sending-whether-fields-filled-or-not/#findComment-178384 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.