On Fri, Apr 05, 2002 at 09:42:37PM -0500, Analysis & Solutions wrote:

> If you want to evaluate the variable $checkboxName, you need to write:
>    
>    $var = "checkbox$cb[$i]";
>    if ($$var == 'validate')
> 
> But, of course, that assumes you actually set the name of your 
> checkbox to "checkboxName" and the value of that checkbox to "validate"

Pardon my following up to myself, but I figured it'd be a good idea to  
do so.  I was initially going to suggest your method of coding seems    
quite wacky.  Then, I figured, hey, let them do what they want.  Now,   
I've thought better of it.  A far simpler way to achieve what it seems
you're trying to do is to use an array in the first place.

<input type="checkbox" name="checkbox['Name']" value="validate" />

Then in your receiving code, you could just do

if ($checkbox['Name'] == 'validate') {

Or,  if you want to loop through each item, as you were in your original 
code:

while ( list($Key,$Val) = each($checkbox) ) {
   if ($Val = 'validate) {
      $msg .= "$Key : $Val\n";
      # or whatever it was you were trying to do...
   }
}

WAY cleaner and WAY more flexible.  Now you can add new items to the 
form without having to name them in your $cb[] array.

Also, FYI, there was no need to set the array using $cb[$i].  Just
doing something like 
   $cb[] = 'some value'; works just fine, with the key being
automatically numbered/incremented, starting at 0.

Enjoy,

--Dan

-- 
                PHP scripts that make your job easier
              http://www.analysisandsolutions.com/code/
         SQL Solution  |  Layout Solution  |  Form Solution
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Ave, Brooklyn NY 11232    v: 718-854-0335    f: 718-854-0409

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to