Re: making checkbox's and radio buttons sticky

From: Date: Sat, 13 Aug 2005 23:25:38 +0000
Subject: Re: making checkbox's and radio buttons sticky
References: 1 2 3 4 5 6 7 8 9  Groups: php.general 
Request: Send a blank email to php-general+get-220569@lists.php.net to get a copy of this message
Support wrote:
ok....I got it!! not wanting to go down the path of the darkside...I inserted the superglobals.. if (isset($_POST['gmev']) && in_array('September 9th', $_POST['gmev'])) so did I get it right?
there are many roads to Rome. using isset() and in_array() is a very good start indeed! (you'd be surprised at how many people don't check vars at all) you might consider either casting $_POST['gmev'] as an array at some stage: $myArr = (array)$_POST['gmev'] or also using is_array() to check that $_POST['gmev'] is actually an array. another technique sometimes used is to suppress the error in cases when you need speed AND you know the error is of no consequence: if (@in_array('September 9th', @$_POST['gmev'])) { // bla } notice 2 @ signs. the first suppresses the warning about possible in correct 2nd param to in_array() the second will suppress the notice if $_POST['gmev'] is not set. be very wary of the @ sign - don't use it lightly, most always using isset() in combination with a is_*() function is much much better (and more correct. also check out the ctype functions: http://php.net/ctype


« previous php.general (#220569) next »