Re: Non selected submited form-array values

From: Date: Sat, 01 Sep 2001 00:44:48 +0000
Subject: Re: Non selected submited form-array values
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-65573@lists.php.net to get a copy of this message
Submitting only checked boxes is just how HTTP works. A cool trick you can use is to do this: name=noticias[$id] value='m' In other words, you can convey *MORE* info by including a specific "key" with each checkbox element from the sending script. For keeping track of previous values, though, I usually have two INPUTs in my form. name=noticias[$id] value='m' name=noticias_old[$id] value='m' Or something similar. If you are worried about security and people submitting bad data, it might be better to use sessions or something to track the user and their "previous" values though. You still want to verify valid input from the user on the new value, of course. -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm ----- Original Message ----- From: Julio Nobrega Trabalhando <inerteARROBAhotmail.com@pb1.pair.com> Newsgroups: php.general To: <php-general@lists.php.net> Sent: Thursday, August 30, 2001 9:34 AM Subject: Non selected submited form-array values > Hi All, > > I already spent too much time trying to solve this one by myself, so I am > in need of a little bit of help. > > I have a form with checkboxes, all with the same name (name="noticias[]"). > When it is submited, only the selected checkboxes become a value on the > array $noticias on the next page. So: > > <checkbox name="noticias[]" value="m" checked> > <checkbox name="noticias[]" value="w"> > > $noticias will have only one value, 'm'. Right? I come to this conclusion, > but I might be wrong. The values are dinamic, which means not always certain > boxes will be checked or have the same value, form by form. So form X can > have 3 checkboxes with different values than form Y with 8 checkboxes. > > Okay. Now I need to compare the submited values with another 'parsed > string', or not if I took the wrong path from the beggining to solve this > problem. For example: > > $string = 'w=1&r=0&m=0'; > parse_str($string); // Will become $w = 1, $r = 0, etc... > > Back with the array $noticias, I need to compare the selected values with > the ones on the parsed string, still mantaining the parts equal to zero. If > array $noticias will only have values with the checked boxes, how can I > 'update' the $string (returning a new one, for example) with the new checked > boxes and still maintain the ones that equals to zero, if the $string can > have an uncertain number of values after parsed? > > That's a hard one, I believe ;-) > > Say, just to clarify, another example: > > $noticias = Array("m","d") > $string = "m=0&d=1&w=1&d=0"; > > The resulted string would need to be: "m=1&d=1&w=0&d=0"; > > A solution I am trying to unfold for dinamic (or uncertain) strings, it to > make a function that one of the parameters is the 'old string', which I > would pass to this function, to serve as a 'base' to be updated with the > values from the form array ($noticias). > > But I am stuck at the part where this old string is compared, and its > values are updated if the form's checkboxs are selected, or not. > > Am I missing some simple function from the manual that can do this for me? > If not, how can I accomplish this result? > > Thanks a lot if you read it until here ;-) > > -- > > Julio Nobrega > > A hora está chegando: > http://toca.sourceforge.net > >

« previous php.general (#65573) next »