|
Posted by Richard Lynch on 01/20/05 21:20
Ben Edwards wrote:
> On Wed, 19 Jan 2005 15:22:55 -0800 (PST), Richard Lynch <ceo@l-i-e.com>
> wrote:
>> Ben Edwards (lists) wrote:
>> > I know this is not strictly speaking a PHP question but it is to do
>> with
>> > a PHP app.
>> >
>> > I have a form with a number of hidden values in it. After the post
>> > print_r( $_POST ) shows all the values except these (this is copied
>> from
>> > 'Show Source' in the browser.
>> >
>> > <input type=hidden name=keyField[mb_memberships][0] value=mb_e_id>
>> > <input type=hidden name=keyValue[mb_memberships][0] value=100000>
>> > <input type=hidden name=keyField[mb_memberships][1] value=mb_id>
>> > <input type=hidden name=keyValue[mb_memberships][1] value=1>
>> >
>> > Any idea why they wont post?
>>
>> The *do* POST, but PHP only handles one level of array references in
>> NAME=xxx
>>
>> You can do something like:
>> <?php
>> while (list($keys, $value) = each($_POST['keyField'])){
>> $keys = explode('][', $keys);
>> list($key1, $key2) = $keys;
>> $realKeyField[$key1][$key2] = $value;
>> }
>> ?>
>
> Almost follow this but not quite. Is this the code used to create the
> hidden HTML input tag
No, you have that correct already (though the " marks would be Good to add)
> or the one to unpack the variable after the
> post.
Yes.
What you are receiving from HTTP/POST/PHP is the same as:
$keyField['mb_memberhips][0'] = 'mb_e_id';
Note the lack of intervening apostrophes you expected:
$keyField['mb_memberhips']['0'] = 'mb_e_id';
PHP only parses POST data to *ONE* dimension.
Same as GET data too.
> What is really spooky is the keys are actually held in a
> variable in an object called keys - your telepathic abilities are very
> impressive;).
Actually, I'd recommend using something more specific than 'keys' -- I
used keys cuz I have no idea what you're doing.
You should NOT use keys, because you DO know what the data is.
'keys' is too generic for Good Programming Style.
> My first thought was when you said PHP only handles one
> level in post was to serialize the array, put the serialized version
> in as a single hidden HTML tag and unserialize at the other end. do
> you reckon this is a goer?
This is also an option if you prefer, though I find it difficult to debug
or follow code logic when I can't use a browser's "View Source" to see all
the variables, so generally just un-pack the 2-D arrays as above.
--
Like Music?
http://l-i-e.com/artists.htm
Navigation:
[Reply to this message]
|