Page 1 of 1

Passing HTML input to php

Posted: Tue Jun 03, 2003 9:20 am
by RicInACloak
I have an HTML page containing multiple check boxes. It also contains a javascript to toggle the checks off and on, or to select all. The javascript requires that all the checkboxes have the same name attribute, although i have given them different id's. this all works fine, but when i click through to a php page, I can only see the last checkbox, in javascript they are treated as an array of controls, and thats roughly what i expected to get in php. $_REQUEST simply doesnt contain what i need, is the re a solution in php (definitely the preferred option), or do i need a different solution in javascript.

Posted: Tue Jun 03, 2003 9:27 am
by d1223m
are you using post or get?

i think that javascript arrays do not get converted automagically. I seem to remember a user note on the php manual pages.

searching for "javascript array" on the whole php site seems to yield results:
http://www.google.com/search?q=javascri ... p.net&l=en

Posted: Tue Jun 03, 2003 9:30 am
by twigletmac
Basically PHP uses the name attribute as it's reference so if they're all the same, (e.g. all have name="checkbox") then you will only ever get the last checked value as each will overwrite the previous one. You could use an array e.g.

Code: Select all

<input type="checkbox" name="checked&#1111;]" value="1" />
<input type="checkbox" name="checked&#1111;]" value="2" />
which will give you an array of values to use in PHP, don't know how this impacts your JavaScript though.

Mac

Posted: Tue Jun 03, 2003 10:05 am
by hedge
I found that I had to explicitly assign the array indexes or otherwise when the form was posted my array would only contain the checkboxes that were on... that made for some interesting bugs when we had multiple arrays in sync with each other.

so instead of:

Code: Select all

<input type="checkbox" name="checked&#1111;]" value="1" />
<input type="checkbox" name="checked&#1111;]" value="2" />
I had to use:

Code: Select all

<input type="checkbox" name="checked&#1111;0]" value="1" />
<input type="checkbox" name="checked&#1111;1]" value="2" />
anyone else run into this? maybe it was just with the older versions of php, haven't tested it in a while.

Posted: Tue Jun 03, 2003 10:13 am
by RicInACloak
PHP now perfect, but unfortunately javascript broken. I think I prefer php working to javascript working.