JSON + PHP + Form Arrays Gotcha

August 21st, 2008

Just a little note mostly to myself, but perhaps someone will find it and save themselves a couple of hours debugging:

I have a part of xemzi.com (search) where the page is loaded first, and then the GET parameters are passed via Ajax to the search routine, updating the central list area and the map in the process.

Normally, when searching from the main search box on the site, you can only choose one area to choose from, which I think is why it took me so long to notice this bug; once you've reached the search results page you can check various boxes in the left column to search different (and this time multiple) categories.

The Bug: if you selected more than one category to search in only the last one would register.

What had happened was I took $_GET and JSON'd it, which resulted in this:

{"module":"entity","search":"1","lang":"","ssquery":"vietnamese","subents":["venue","event"]}

all great so far, until I came to pass that object reference through Ajax.Updater as the new parameters for the search results, at which point I only received the last value ('event') of subents.

What had happened was that JS had removed the final '[]' on subents, so on the second GET it wasn't recognized by PHP as an "array form field." To rectify the situation I need to

params["subents[]"] = params["subents"]; params["subents"] = '';

Problem solved.

2 Responses to “JSON + PHP + Form Arrays Gotcha”

  1. My maps Says:

    Blog added to my favorites! :-)

  2. asydayjobs Says:

    We offer online and Faxless Payday Loans that you can receive the same day.The best Lenders from USA.http://www.easyfaxlesspaydayloan.com

Leave a Reply