Controller doesn't fill the form elements from hydrated objects that are attached to the form

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Controller doesn't fill the form elements from hydrated objects that are attached to the form

DimaD
This post has NOT been accepted by the mailing list yet.
I have a form that has two fieldsets. The 2 fieldsets are basically for party-related info (party = person or company) and phone-related info. The fieldsets are called using the init method of the form like this

class PhoneRegistrationForm extends RegistrationForm implements InputFilterAwareInterface
{
    public function __construct()
    {
        parent::__construct();

        $this
            ->setAttribute('method', 'post')
            ->setHydrator(new ClassMethods(false))
            ->setObject(new Phone());

        $this->add([
            'type' => 'Zend\Form\Element\Button',
            'name' => 'submitButton',
            'attributes' => [
                'id' => 'submit-phone-button',
                'class' => 'btn2 submit-button',
                'type' => 'submit',
            ],
            'options' => [
                'label' => 'Сохранить',
            ],
        ]);
    }

    public function init()
    {
        $this->add([
            'type' => 'Parties\Forms\Fieldsets\PhoneFieldset',
            'name' => 'phoneFieldset'
        ]);

        $this->add([
            'type' => 'Parties\Forms\Fieldsets\PartyIdAndRolesFieldset',
            'name' => 'partyFieldset'
        ]);
    }

In the controller's edit action, I create and hydrate the PhoneObject and PartyObject with the values from the database (PhoneObject and PartyObjects are just collection of getters and setters). I then set the hydrated objects to the fieldsets:

$this->form->get('phoneFieldset')->setObject($phone);
$this->form->get('partyFieldset')->setObject($party);

And here is my problem, if I return the instance of form to the controller, the form inputs have no values that come from the attached hydrated objects.

How to get the form inputs filled with the values from the hydrated objects attached to fieldsets?

I tried binding $this->form->bind($phone), but to no avail. The fieldsets have ClassMethods() hydrator set too.

What could the problem be? Any clues?