Passing HTML input to php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RicInACloak
Forum Newbie
Posts: 2
Joined: Tue Jun 03, 2003 9:20 am

Passing HTML input to php

Post 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.
User avatar
d1223m
Forum Commoner
Posts: 80
Joined: Mon Mar 31, 2003 5:15 am
Location: UK, West Sussex

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post 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.
RicInACloak
Forum Newbie
Posts: 2
Joined: Tue Jun 03, 2003 9:20 am

Post by RicInACloak »

PHP now perfect, but unfortunately javascript broken. I think I prefer php working to javascript working.
Post Reply