Jump to content

Wireinput only allows one-dimensional arrays - why?!


Rob
 Share

Recommended Posts

I've been developing an Inpuitfield/Fieldtype combo that allows me to input multiple sets of data, and I'm using JQuery to add another "set" of data into the form markup but I've run into a problem becasue I'm using multi-deimnesional array names for the form fields.  This doesn't get processed correctly by PW and when I look at the WireInput class it mentions only allowing single-dimensional arrays.

Is there a good reason for this?  Multi-dimensional arrays in forms are pretty useful and I can't work out (off the top of my head) why this would be restricted in this way.

For example:

<input name="fieldname[phonenumber][] />
<input name="fieldname[phonenumber][] />

This will return an empty array for the field value in the WireInput instance passed into ___ProcessInput() method.

Is there a specific reason?  I can manage by directly accessing the POST array, but it'd be nicer to use a native PW approach.

Link to comment
Share on other sites

If I make WireInputData::cleanarray() recursive by removing the check for array line and then adding this...

If(is_array($value)) return $this->cleanarray($value);

...then I get the result I would expect.  Is this behaviour likely to damage other parts of the system?

Link to comment
Share on other sites

Code mistake again!!

In fact, all I had to do was remove the code that checks for an array and returns (thus not allowing multi-dimensional arrays) and I now get the behaviour I would expect.

This brings me back to the question - why disallow this behaviour?

Link to comment
Share on other sites

I can't speak for Ryan, and I'm not sure. I guess it's to simplify things on not have endless dimensional for sake of the change tracking? Anyhow, can't you just use $_POST $_GET? Or are you really needing processInput?

On a side note:

Why doing quadruple posts?

Please use the edit button to add things.

Thanks

Link to comment
Share on other sites

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.

Thanks,

Ryan

  • Like 5
Link to comment
Share on other sites

  • 1 year later...
  • 2 years later...
  • 5 months later...
  • 1 year later...
  • 2 years later...
  • 10 months later...

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...