Re: HTML Forms question...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> OK.  If I am using the POST method and the checkbox 'name' for all
> of the checkboxes is 'system', how do I access the results?  I am
> researching on the PHP site trying to figure out what this array is, and
how
> I access this if the index name is the same for all elements.  I am hoping
> that this data will be in an array and I can simply loop through the
> contents of the array.  If this data is stored in a hash (Perl word for
this
> type of array, not sure if it's the same in PHP), how do I access this
data
> since the index for every element would be the same?
> I am SURE that I am probably missing some important conceptual
> issues here, but still learning as I go.  Unfortunately, this probably
means
> that I will be completely rewriting this application at least once in the
> future.  Oh well, live and learn.  Thanks again for the help.

If you have multiple checkboxes with the same 'name' then you should name
then with brackets, [], such as 'system[]'. This will tell PHP to make the
results an array when the form is submitted.

For any of the 'submit[]' checkboxes that are checked, they will be present
in PHP array on the processing page. Those unchecked will not be present.

Say you have the following.

<input type="checkbox" name="submit[]" value="1">One
<input type="checkbox" name="submit[]" value="2">Two
<input type="checkbox" name="submit[]" value="3">Three

If the method on your form is POST, and the user checks One and Three, then
you'll have the following values in PHP on the ACTION page of the FORM.

$_POST['submit'][0] ==> 1
$_POST['submit'][1] ==> 3

>From that data, though, there's no way to tell that checkbox "Two" was not
checked, unless you go through and check all of the values. That's fine for
small forms, but a hassle for large ones.

You could also name your checkboxes like this:

<input type="checkbox" name="submit[1]" value="1">One
<input type="checkbox" name="submit[2]" value="2">Two
<input type="checkbox" name="submit[3]" value="3">Three

and if the user checks one and three again, you'll get

$_POST['submit'][1] ==> 1
$_POST['submit'][3] ==> 3

Hopefully that clears some things up. If you have any other questions, just
ask.

---John Holmes...


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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux