Welcome Guest, Not a member yet? Register   Sign In
Brackets in field names: Input class failure
#1

[eluser]Madmartigan1[/eluser]
Looks like brackets in field names aren't being handled correctly in the Input class? I'm sure this issue has always existed, but it's only become an issue for me recently.

This issue is brought up here and here as well, just to cite very recent posts.

Input::_fetch_from_array() is used to grab $_POST items by array key, but this doesn't work as expected for field names with one or more brackets, as the $_POST value will be a multidimensional array.

Consider the following example:


Code:
// Pretend we have the following inputs
// <input name="user[phone][cell]" />
// <input name="user[phone][home]" />

$this->input->post('user[phone][cell]'); // will return false
// This is some ugly syntax anyways
// Its looking for this: $_POST['user[phone][cell]'];

$_POST['user']['phone']['cell']; // will return the correct value

$data = $this->input->post('user');
$cellphone = $data['phone']['cell']; // will also work

I understand that it's possible to work around this by simply NOT using indexes, i.e. <input name="user_phone_cell" />, but anyone who knows what I'm talking about will probably agree that this is a major pain and constricts the developer.

I'm thinking that there are various bugs as a result of this, like set_value().
I ran into issues with this by looping through arrays of field data (name, label, rules, value, etc.) to set rules and repopulate values.

Anyone else have issues with this?
#2

[eluser]Jacob Graf[/eluser]
Bump

This makes dealing with multidimensional input arrays a pain in the butt. It also opens up your application to inconsistencies because now I am forced to use

Code:
$_POST['field']['array1']['array2']

Instead of

Code:
$this->input->post('field[array1][array2]')

Erghh. Anyone else have any thoughts on this one?
#3

[eluser]jaydisc[/eluser]
I'm suffering the same issue. Are we doing it wrong?
#4

[eluser]jason.wolfsmith[/eluser]
I haven't figured out a way to retrieve posted data using this format
Code:
$this->input->post('input_name[]')

But you can do this:

Code:
$fields = $this->input->post();

It is not much different than just using $_POST because you still have to use
Code:
$fields['field']['array1']['array2']
but you get the added security codeigniter provides.




Theme © iAndrew 2016 - Forum software by © MyBB