Re: Retrieving the multiple values set by a form



Girish wrote:
Ron Barnett wrote:

In the example you have given, which equates to a Get, the variables will
indeed overwrite each other with only the last value surviving, as stated by
lorento.



Hi Ron and everyone else,

Thanks for your response. Let me expand a bit on my requirement. I have
a dynamically generated form where I am now trying something similiar.
To wit:

<input name='inp[0]' type='checkbox' value='first value'>
<input name='inp[1]' type='checkbox' value='second value'>
<input name='inp[2]' type='checkbox' value='third value'>
.
.
etc

Basically, I present a user with a dynamically generated checklist and
I am trying to see all the values that he has checked.


once this is received by your PHP script the values may be retrieved :

$myArray = $_REQUEST('ip'); // note no subscripts required

$myArray['0'] will contain 'first value', $myArray['1'] the second value,
and so on



Doing as you have suggested, count($myArray) gives the correct number
of values ticked.

But only $myArray['0'] is set!
$myArray['1'], $myArray['2'] , ..., etc are not set!

Not to flame or anything, I AM quite surprised by how arcane processing
a checklist in php is turning out to be. :-)


Thanks again!
Girish


Girish,

First of all, it should be $myArray[0], not $myArray['0']. It has a numeric index. And the fact count($myArray) has the correct value indicates the values are correct.

Also, the way you have it coded, if the 'second value' checkbox is not checked, myValue[1] will not be set and you'll get a notice if you try to use it. Unless you absolutely have to have the indexes like that, a better way is to use:

<input name='inp[]' type='checkbox' value='first value'>
<input name='inp[]' type='checkbox' value='second value'>
<input name='inp[]' type='checkbox' value='third value'>

Now inp[0] will contain the value from the first checked box, imp[1] will contain the value from the second checked box, etc.

Also, I agree with Anthony but for different reasons. I suggest you use POST instead of GET. Not because of the array (it should work in either), but because it can get to be quite a long URL if the user checks several boxes.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: Retrieving the multiple values set by a form
    ... lorento. ... Thanks for your response. ... Let me expand a bit on my requirement. ... once this is received by your PHP script the values may be retrieved: ...
    (comp.lang.php)
  • Re: England team for ABs
    ... playing career and left the door open for him to expand about how good ... he was and what he'd done to give credence to his thinly veiled ... Your response was that, and then a statement about how it was better than ... Hence why I said I left the door open for him to expand about how good ...
    (rec.sport.rugby.union)
  • RE: Change documents in word with VBA
    ... Jay, Thanks for the response. ... It helped some but I need to expand on my ... The info I need to put in a seprate file is not exactly the same info that ...
    (microsoft.public.word.vba.general)
  • Re: PopUp help
    ... To expand on the other response, you would probably use something like this in the text box Before Update event: ... MsgBox "Status box must be checked" ...
    (microsoft.public.access.gettingstarted)
  • Re: RedHat CEO says home users shouldnt use Linux
    ... "Jeffrey Silverman" wrote in message ... > You have said effectively this same thing in response to several other ... > forks in this thread. ... Could you expand on this? ...
    (alt.os.linux.redhat)