Jump to content

Newbie Question


jdbfitz

Recommended Posts

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();	
	}			

}		

 

Link to comment
https://forums.phpfreaks.com/topic/76063-newbie-question/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/76063-newbie-question/#findComment-385217
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.