Jump to content

Getting multiple checkbox values within ProcessWire


teppo
 Share

Recommended Posts

As the title says, I'm trying to get multiple checkbox values via PW:

<form method="GET">
<input type="checkbox" name="bs[]" value="1" />
<input type="checkbox" name="bs[]" value="2" />
<input type="submit" />
</form>
<?php
var_dump($input->get->bs);

When I submit that form, it results in URL like this: "...?bs%5B%5D=1299&bs%5B%5D=1300". URL encoding makes it a bit hard to read, but that should still work. Var_dump outputs following:

string(5) "Array"

It seems that PW converts GET array to string "Array". Same thing happens if I use $_GET['bs'] instead of $input. When I tried putting a simple test script that doesn't use PW this is the result of same query (with URL encoded and all) - and this is exactly what I was expecting PW to give me too:

array(2) { [0]=> string(4) "1299" [1]=> string(4) "1300" }

So, does anyone know how to bypass this behavior? :)

Edit: this has been solved -- the problem wasn't ProcessWire, it was the way I was passing variables around, which eventually ended up flattening arrays to strings. Long story short: ProcessWire itself handles multiple checkbox values / GET (and probably POST) arrays just fine.

Sorry folks, my mistake! :)

Edited by teppo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...