note 30699 deleted from function.sizeof by colder
| From: | colder@php.net | Date: | Tue, 16 Jan 2007 14:21:41 +0000 |
| Subject: | note 30699 deleted from function.sizeof by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-121797@lists.php.net to get a copy of this message | ||
Note Submitter: gramo at skina dot com dot co
----
[ Editor's Note: Unchecked boxes are not passed to the form action page at all. Therefore if
only two of the four checkboxes below are checked, only two will be passed to the action page and
sizeof/count will return two. grammo's statement that the array contains NULL elements is
incorrect. ]
When you have a php page receiving data from a form with an array like:
--------8<----------------8<----------------8<--------
<FORM ACTION="receiver.php" METHOD=POST>
<INPUT TYPE=CHECKBOX NAME="arreglo[0]">Thing #1
<INPUT TYPE=CHECKBOX NAME="arreglo[1]">Thing #2
<INPUT TYPE=CHECKBOX NAME="arreglo[2]">Thing #1
<INPUT TYPE=CHECKBOX NAME="arreglo[3]">Thing #4
<INPUT TYPE=SUBMIT>
</FORM>
--------8<----------------8<----------------8<--------
And you just pick Thing #2 and Thing #4 like:
--------8<----------------8<----------------8<--------
[ ] Thing #1
[X] Thing #2
[ ] Thing #1
[X] Thing #4
[OK]
--------8<----------------8<----------------8<--------
When you count the number of elements in arreglo {NULL, "on", NULL, "on"} you
receive just a 2 for answer, because NULL counts as no element for the count function.
These have huge importance when you generate the forwarding form with a database query and you need
to know how many elements does the script generate.
The only way to fix these problem is by adding a new element at the form in this way:
--------8<----------------8<----------------8<--------<FORM
ACTION="receiver.php" METHOD=POST>
<INPUT TYPE=HIDDEN NAME="arreglo_size" VALUE="4">
<INPUT TYPE=CHECKBOX NAME="arreglo[0]">Thing #1
<INPUT TYPE=CHECKBOX NAME="arreglo[1]">Thing #2
<INPUT TYPE=CHECKBOX NAME="arreglo[2]">Thing #1
<INPUT TYPE=CHECKBOX NAME="arreglo[3]">Thing #4
<INPUT TYPE=SUBMIT>
</FORM>
--------8<----------------8<----------------8<--------