aeafisme23 Posted July 19, 2008 Share Posted July 19, 2008 Right now I am using Javascript along with PHP to process a simple contact form. It works great but apparently some people think it is fun to press space bar on each input field to get around validation so i get alot of emails that are blank forms. So i would like to in turn put up some php programming to prevent empty fields and by empty that also means that pressing the space button <--- see spacing would get around this issue. Please go to my contact form if you want to try it yourself and i will settle with a few emails: http://www.loonar.net/contact.php I am assuming this is going to take the approach of using empty or something about testing a string? Any point in the right direction would be great ( a previous forum posting, examples, or just advice would be great. Thank you) My code can be found here for the form ( i dont think you need the processing page but if you do ill post it in a reply) Javascript validation but would like php to back up serverside if js is disabled: <script> function checkcontactus() { if (document.forms.contactus.elements['fullname'].value.length == 0) { alert('Please enter a value for the "Your Name" field'); return false; } if (document.forms.contactus.elements['email'].value.length == 0) { alert('Please enter a value for the "E-MAIL" field'); return false; } return true; } </script> More Code: [code] <td bgcolor="#FFFFFF" valign="top" width="493"><center><img src="images/welcome.jpg" width="485" height="21" border="0"></center> <p><span class="black">Please fill out all the information below and we will get back to you as quickly as possible.</span></p> <script> function checkcontactus() { if (document.forms.contactus.elements['fullname'].value.length == 0) { alert('Please enter a value for the "Your Name" field'); return false; } if (document.forms.contactus.elements['email'].value.length == 0) { alert('Please enter a value for the "E-MAIL" field'); return false; } return true; } </script> <center><img src="images/hr.gif" width="480" height="10" border="0"></center><br> <form name="contactus" method="POST" action="email.php" onSubmit="return checkcontactus()"> <center><table width="480" cellpadding="0" cellspacing="0" border="0"> <tr> <td width="100" valign="middle"><p><span class="bold">Your Name:</span> </p></td> <td width="380"><p><input name="fullname" size="30"> *required field*</p></td> </tr> </table> <br> <table width="480" cellpadding="0" cellspacing="0" border="0"> <tr> <td width="100" valign="middle"><p><span class="bold">Email:</span> </p></td> <td width="380"><p><input name="email" size="30"> *required field*</p></td> </tr> </table> <br> <table width="480" cellpadding="0" cellspacing="0" border="0"> <tr> <td width="480" valign="middle"><center><p><span class="bold">Service or Request Desired:</span><br> <select size="1" name="service"> <option value="No Request Selected">Please Choose a Request</option> <option value="Business Cards">Business Cards</option> <option value="Photo Retouch">General Question</option> <option value="Logo Design">Logo Design</option> <option value="Photo Retouch">Photo Retouching</option> <option value="Web Design">Web Design</option> <option value="Web Hosting">Web Hosting</option> <option value="Video Editing">Video Editing</option> <option value="Other">- Other -</option> </select></p></center></td> </tr> </table> <br> <table width="480" cellpadding="0" cellspacing="0" border="0"> <tr> <td colspa valign="top"><center><p><span class="bold">Please explain the services you need in detail:</span></p></center></td> </tr> <tr> <td valign="top"><center><textarea cols="45" rows="7" name="other"></textarea></center></td> </tr> </table> <br> <table width="480" cellpadding="0" cellspacing="0" border="0"> <tr> <td width="115"></td> <td width="150"><input type="submit" value="Request Information"></td> <td width="45"></td> <td width="100"><input type="reset" value-"Reset"></td> <td width="75"></td> </tr> </table></center> <br> </form> <p><span class="black">* Denote a Required Field - Please fill out all fields to submit form.</span> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/115622-solved-validating-an-input-field/ Share on other sites More sharing options...
ignace Posted July 19, 2008 Share Posted July 19, 2008 validate using: http://be.php.net/manual/en/book.ctype.php filter using: http://be.php.net/manual/en/book.filter.php Quote Link to comment https://forums.phpfreaks.com/topic/115622-solved-validating-an-input-field/#findComment-594370 Share on other sites More sharing options...
aeafisme23 Posted July 21, 2008 Author Share Posted July 21, 2008 bump* Quote Link to comment https://forums.phpfreaks.com/topic/115622-solved-validating-an-input-field/#findComment-595763 Share on other sites More sharing options...
DarkWater Posted July 21, 2008 Share Posted July 21, 2008 if (empty(trim($_POST['text'])) { //blah blah blah } Quote Link to comment https://forums.phpfreaks.com/topic/115622-solved-validating-an-input-field/#findComment-595768 Share on other sites More sharing options...
aeafisme23 Posted July 21, 2008 Author Share Posted July 21, 2008 Thank You Dark! Quote Link to comment https://forums.phpfreaks.com/topic/115622-solved-validating-an-input-field/#findComment-595774 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.