Jump to content

[SOLVED] Multidimensional Arrays in HTML POST Forms


kael.shipman

Recommended Posts

Hey everyone,

 

I browsed the other topics relating to this and found a few mixed responses, but nothing useful. Here's my (extremely frustrating) problem:

 

I've built a changeLog system for an admin site in javascript that all works fine and everything, and at the end the JS dumps it's changeLog to a multidimensional array in an HTML POST form and submits the form. It works flawlessly in FireFox and Safari on Mac, but on windows - both Internet Explorer and FireFox - it seems to crash randomly. Debugging is maddening because it seems to crash in between actions. More on that later, but for now, here's an example of what I'm trying to send:

 

<form action="process.php" method="post">
<textarea name="chngs[0][albID]">1</textarea>
<textarea name="chngs[0][name]">An Existing Album (but changed)</textarea>
<textarea name="chngs[0][desc]">Here's a changed description of the album</textarea>
<textarea name="chngs[1][albID]">2</textarea>
<textarea name="chngs[1][pictures][1][name]">An existing picture name under album 2 (but changed!)</textarea>
<textarea name="chngs[1][pictures][-1][name]">A new picture!!</textarea>
<textarea name="chngs[1][pictures][-1][file]">Path/to/new/picture</textarea>
</form>

 

Ignore any problems with the actual data that you see (like the file path). It seems to work when I limit the depth of the array to 2 (like if I just sent the top three textareas and scrapped the rest), but I haven't been able to nail it to that and I couldn't explain why in the hell they would choose to limit the depth at all, let alone to such a small number.

 

Like I said earlier, it crashes right in the middle of things. I have an onsubmit listener that fills the form right before it's submitted, and I put an alert right at the end of that before it returns true to sumbit. The alert fires every time. I can even see that the contents of the form are correct by viewing the innerHTML property of the form, but then the browser just hangs after that. I tried putting a var_dump($_POST); die(); sequence right at the top of the file before anything else happens, but it never even gets there.

 

Is there anything I can do to fix this without rewriting my entire structure? Or maybe even something that would force me to rewrite, but just not that much? Most importantly, can anyone actually explain why this works on Mac but not on windows?

 

Thanks,

Kael

Link to comment
Share on other sites

Deep multi-dimensional arrays may be pushing the limits of something.  An option may be to serialize the array before submitting it, or otherwise encode it yourself.  Google shows that a few people have written simple javascript implementations of a php serializer.

Link to comment
Share on other sites

Cool, thanks! Any insight into why there might be limits at all? I agree with another user on here who said that the array should be entirely server-side. It seems to me that HTML passes a name string and that it's up to PHP to say, "yep; that's an array, and here's how it's structured." Maybe it's not so simple....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.