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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.