Re: Passing arrays

From: Date: Tue, 06 May 2003 07:43:16 +0000
Subject: Re: Passing arrays
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-19777@lists.php.net to get a copy of this message
I've got same problem (with passing arrays) - I solved it by passing each array item separately (with <input> directive). For some arrays I decided to use sessions. Is there any other possibility? 5o Metin Kale wrote: > Hello all.. > > I have a web form that requires users to check a checkbox next to Things To Do. > > Example: > > [] Ski > [] Bike > [] Read > > etc. > > The <input> for these is: > > <input type=\"checkbox\" name=\"mychoices[]\" > value=\"ski\"> Ski > <input type=\"checkbox\" name=\"mychoices[]\" > value=\"bike\"> Bike > <input type=\"checkbox\" name=\"mychoices[]\" > value=\"read\"> Read > > When I submit the form, an array called $mychoices is created. Up until > that point, everything works. I do a foreach() such as: > > foreach ($mychoices as $m) > { > echo "$m<br>"; > } > > This displays the content of the array fine. What I want to do is display > this array so that the user can review what he/she entered (such as above) > and then click a submit button to actually send the data to a form that > would enter the data into the database. The problem I'm having is sending > the same array through another submit. The code I have for the second form is: > > echo " > <form method=\"post\" action=\"submitchoices.php\"> > <input type=\"hidden\" name=\"mychoices\" > value=\"$mychoices\"> > <input type=\"submit\" value=\"submit\"> > </form> > "; > > I get the following result: > > Warning: Invalid argument supplied for foreach() in > e:\web\htdocs\maindesk\admin\deleteatt1.php on line 6 > > I can understand why I get this error because it's not sent as an array > (name=\"mychoices\" and not name=\"mychoices[]\"). But when I do add the > [] at the end of mychoices, it just ignores the array. > > I tried to be as clear as possible.. hopefully someone can help me. I > think I could just recreate a new array while doing the foreach, but I'm > wondering if there is a simpler way. > > Thanks, > Metin Kale -- Mgr. Peter Misun MicroStep-MIS, Ilkovicova 3, 841 04 Bratislava, Slovakia tel: +421/ 2/ 602 00 127, 111, fax: +421/ 2/ 602 00 180

« previous php.windows (#19777) next »