ZF- How to access subform elements and set its values

675 Views Asked by At

Good day to all! What I have here is setting up subform elements and it works fine.

//Setting SubForm element    
$subForm = new Zend_Form_SubForm();
$subForm->setName('sampleSubForm');
$subForm->addElement('text', 'test', array(
           'value' => 'someValue',
           'name' => 'test',
           'belongsTo' => 'sampleSubForm',
           'size' => '1',
           'maxLength' => '1',
           'decorators' => array('ViewHelper'),
        ));
$this->form->addSubForm($subForm, 'sampleSubForm');

I'd still keep fiddling and wondering how to access subform elements upon form submission, to set its value. Cheers and happy coding! thanks

1

There are 1 best solutions below

0
On BEST ANSWER

Although it is not clear what $this is, the following should work:

$this->form->getSubForm('sampleSubForm')->test->setValue('some value');