pyrocms/pyrocms — pull request #2021 by dadaxr (2012-11-17 19:49:28+00:00)
Title: 2.1/develop

widgets fields were already supporting array but in a wrong way : let me explain :

```php
...
//my_widget.php
...
/**
* $fields array for storing widget options in the database.
* values submited through the widget instance form are serialized and
* stored in the database.
*/
public $fields = array(
array(
'field' => 'field_name',
'label' => 'field_label',
'rules' => ''
),
array(
'field' => 'arr[]',
'label' => 'an array',
'rules' => ''
),
array(
'field' => 'arr2[a_key]',
'label' => 'a field stored in a array fashion',
'rules' => ''
),
array(
'field' => 'arr3[a_key][]',
'label' => 'an array stored in another array',
'rules' => ''
),
);
```

When we did something like that, the data were correctly stored in the database ( because the Widget library use the serialize method )

But when we want to get these data back (to the front_panel widget view for example )
... there were problems...

the $options var was not correctly "builded", actually we were retrieving something like :

```php
$options = array(
'field_name' => 'value',
'arr' => array(...),
'arr2' => array("a_key"=> "val2"),
'arr3' => array("a_key"=> array(...) )
)
```
Even if it seems quite good, this is not the way codeigniter works ( see : http://codeigniter.com/user_guide/libraries/form_validation.html , section : "Using Arrays as Field Names"

we are expecting to retrieve something like :

```php
$options = array(
'field_name' => 'value',
'arr[]' => array(...),
'arr2[a_key]' => "val2",
'arr3[a_key][]' => array(...)
)
```

this is what this pull request do :)