Re: ISSET() question
- From: Norman Peelman <npeelman@xxxxxxxxxx>
- Date: Thu, 28 Feb 2008 22:31:46 -0500
Tony wrote:
major wrote:The following code processes a blank field as though it has some value
and proceeds as though it was set to some value.
Apparently isset() is not working, because it thinks that a blank text
field is set to something.
Yes, if the value of a field is "", then it is still set. You would want to test for both:
if ( isset($_POST['name']) && ($_POST['name'] != "") ) ...
Or, if you want to count " " as blank:
if ( isset($_POST['name']) && (trim($_POST['name']) != "") ) ...
There may be a more efficient way to do this - anyone know of one?
Yes, validate it with a regex also:
$name = (isset($_POST['name']) && eregi('^[a-zA-Z]${2,25}',$_POST['name'])) ? $_POST['name'] : false;
if (!$name)
{
....
}
would check to see if the post variable has been set and if it matches a string of alpha a-z (upper & lower case), and is at least 2 characters but not more than 25 characters in length. If not it's set to false and you take appropriate action.
--
Norman
Registered Linux user #461062
.
- References:
- ISSET() question
- From: major
- Re: ISSET() question
- From: Tony
- ISSET() question
- Prev by Date: Re: ISSET() question
- Next by Date: PHP Ecommerce
- Previous by thread: Re: ISSET() question
- Next by thread: Soap server
- Index(es):
Relevant Pages
|