jdbfitz Posted November 5, 2007 Share Posted November 5, 2007 I am new to PHP and just wrote what I think might be a good Function for checking the lengths of specific form fields submitted. Just wondering if anyone might check out this code and give me some niput as to whether it is good, bad, could use help etc. Thanks JD function check_Length() //function to check the lengths of the fields submitted { if(strlen($name) > 25) { $name = ""; $error1 = "The NAME you entered is too long. The name must be 25 characters or less. Please try again"; } if(strlen($phone) < 10 && > 14) { $phone=""; $error2 = "The PHONE NUMBER you entered is too long. The phone number must be 10 to 14 characters in length. Please try again"; } if(strlen($email) > 30) { $email=""; $error3 = "The EMAIL you entered is too long. The name must be 30 characters or less. Please try again"; } if(strlen($message) > 256) { $message=""; $error4 = "The MESSAGE you entered is too long. The name must be 256 characters or less. Please try again"; } if($name = "" || $phone="" || $email="" || $message="") { show_PageAgain(); } } Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted November 5, 2007 Share Posted November 5, 2007 Personnaly I use a switch statment and use an array of field names and their requirement (normally a regular expression) which to check against. Quote Link to comment Share on other sites More sharing options...
NoSalt Posted November 5, 2007 Share Posted November 5, 2007 This is actually something I would handle with the HTML: <input type="text" name="name" maxlength="25" /> <input type="text" name="phone" maxlength="14" /> <input type="text" name="email" maxlength="30" /> <input type="text" name="message" maxlength="256" /> Of course you'll need to check the "phone" for less-than 10 with php or javascript but this will limit what the users can even input. You must remember that users are dumb and the less latitude you give them the better. Quote Link to comment 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.