Jump to content

$input variable cannot get a two dimensional input form element


Recommended Posts

Posted

I have a form with a checkboxes input field, look something like

<input name="choices[1276][]" value="1280" type="checkbox">
<input name="choices[1276][]" value="1285" type="checkbox">
<input name="choices[1276][]" value="1292" type="checkbox">

If I use ordinary PHP fucntion $_POST['choices'], I could get this value.

If I use pw's way $input->post['choices'], i got nothing

I used sizeof to check

sizeof($_POST['choices'])   ->  returned 1 is any of a checkbox is checked

sizeof($input->post['choices'])   ->  returned 0 if a checkbox is checked.

Posted

Does anyone know if there has been an Github issue created for this?  If so, can you please reference in this post?  If not, can you open an issue?

Posted

A couple of relevant posts:

https://processwire.com/talk/topic/691-wireinput-only-allows-one-dimensional-arrays-why/

https://processwire.com/talk/topic/7867-input-and-associative-array-issue/

From Ryan:

The main reason it's not there is just because $input is another layer on top of $_POST (or $_GET or $_COOKIE) and I wanted to limit the overhead of it as much as possible, at least until we needed it. :) Didn't want to enable the possibility of someone posting endless multidimensional arrays from a security standpoint. But ultimately if the need was there, I would add it. And now that its come up, we might as well add it. :) Probably what I will do is just limit the recursion to 2 or 3 levels to keep it safe. I don't see any potential issues with adding it. If you've had the need for it, then I'm sure others will to. If you want to submit a pull request, I'll bring it into the core. Otherwise, I'll plan to add and commit an update to the core soon.
  • Like 2
Posted

Is this happening to variables passed to wireRenderFile too? I experienced such an issue but haven't investigate further.

Posted

That shouldn't cause that, thanks. I'll re-check when it happens again but I guess there's something other that interferes.

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
  • Recently Browsing   0 members

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