# Binding a Zend\\Form\\Form to a hierarchical ArrayObject without using fieldsets

**URL:** <https://discourse.laminas.dev/t/binding-a-zend-form-form-to-a-hierarchical-arrayobject-without-using-fieldsets/811>\
**Category:** Components & MVC\
**Tags:** zend-form, zend-mvc\
**Created:** [November 9, 2018, 5:29pm UTC](https://discourse.laminas.dev/t/binding-a-zend-form-form-to-a-hierarchical-arrayobject-without-using-fieldsets/811 "2018-11-09T17:29:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidmintz](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/davidmintz/32/213_2.png) [@davidmintz](https://discourse.laminas.dev/u/davidmintz)\
**Post date:** [November 9, 2018, 5:29pm UTC](https://discourse.laminas.dev/t/binding-a-zend-form-form-to-a-hierarchical-arrayobject-without-using-fieldsets/811/1 "2018-11-09T17:29:13Z")

</div>

I have gotten myself into a bit of a bind here [conceptual pun intended]. Rather than pasting a ton of code, I’d like to pose this as a sort of theoretical question.

The case is that I want to make a front end for users to be able to configure event handlers where the events are, well, fine-grained with conditional logic. So a configuration setting might look something like,

```
some_event.condition1.condition2.condition3.do_something = true|false

```

I took it into my head to make a hierarchical data structure out of this, e.g.,

```
$config = [
    'event_foo' => [
        'condition_a' => [
            'condition_p' => [
                'do_action_x' => $boolean,
                'do_action_y' => $boolean,
            ],
            'condition_q' => [
                'do_action_x' => $boolean,
                'do_action_y' => $boolean,
            ]
        ],
        'condition_b' => [
            'condition_p' => [
                'do_action_x' => $boolean,
                'do_action_y' => $boolean,
            ],
            'condition_q' => [
                'do_action_x' => $boolean,
                'do_action_y' => $boolean,
            ]
        ],
    ]
    /** etc */
];

```

and now the general issue I am having with this wildly complicated scheme is that it’s… wildly complicated. But seriously, folks – I made a JSON object out this for persistence, read it back from disk and `json_decode()` it, and then tried using the data to populate a Zend\Form\Form containing about 27 checkboxes named using array notation, e.g.,

```
name="some_event[condition_x][condition_y][do_something]"

```

Creating these elements requires `foreach` loops nested four levels deep, but it works. But populating the form – that’s not working. I have set the hydrator = `ArraySerializable`, I instantiate my ArrayObject and `bind()` the form to it, `$form->setData($object)` on it, etc, etc, no luck. No errors or anything, just quiet failure to set the form values.

I think this form initialization should work before getting into input filters and validation, so I assume that is not the problem.

So: do I have to make multiple nested Fieldsets in order to populate a form from a hierarchical ArrayObject? Or is there some way that I am overlooking?

Thanks.

---

<div class="post-metadata">

**Author:** ![davidmintz](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/davidmintz/32/213_2.png) [@davidmintz](https://discourse.laminas.dev/u/davidmintz)\
**Post date:** [November 9, 2018, 9:25pm UTC](https://discourse.laminas.dev/t/binding-a-zend-form-form-to-a-hierarchical-arrayobject-without-using-fieldsets/811/2 "2018-11-09T21:25:32Z")

</div>

OK I think I might have a (if not _the_) solution: compromise. For each top-level key in my configuration, one fieldset. Within each of those, no more nesting: flatten out the names using dot notation. If I’m right I will be so excited, I’ll be sure to come back and tell you more about it. 😀

**UPDATE:** Correct me if I’m wrong but I think the takeaway is: you can’t do what I was trying to do (with nested arrays, object hydration and form-binding without nesting fieldsets), so don’t try.
