Reputation: 139
I have created new class which extends Zend_Form, but when I´m trying to iterate through all Elements in my new custom form (or only count them all) the result is always 0.
class Application_Form_ZendForm extends Poroform_Form {
public function init() {
parent::init();
$this->setAttrib('id', 'contact-form');
$this->addElement('text', 'textt', array(
'label' => 'Foo',
'value' => 'test',
"attribs" => array(
"icon" => "icon-append fa fa-user",
"section" => "col col-6"
),
));
}
}
class Poroform_Form extends Zend_Form {
public function __construct($options = null) {
parent::__construct($options);
}
public function init() {
$this->setAttrib("class", "smart-form");
$this->setAttrib("novalidate", "novalidate");
$this->setAttrib("elem_count", count($this->getElements())); //why is result 0?
$this->addElementPrefixPath('Poroform_Form_Decorator_', '/Poroform/Form/Decorator/', 'decorator');
$this->setElementDecorators(Array('SmartadminInput'));
foreach ($this->getElements() as $element) { //not working
$element->setAttrib("test", "aaa");
}
}
}
So Am I looking for custom forms by wrong side?
Upvotes: 1
Views: 147
Reputation: 14184
You need to call parent::init()
in Poroform_Form::init()
before you iterate over the form elements.
If you follow the flow, you'll see that in Poroform_form::init()
at the point at which you are iterating over the form elements, you truly have not yet added any. All the elements are added in the parent Application_Form_ZendForm
.
Upvotes: 1