Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7172
User: @Martin-P
Created On: 2015-01-31T00:36:54Z
Updated At: 2015-11-06T20:07:59Z
Body
I think there should be some refactoring of adding elements to Zend\Form, because inputs can be represented by different classes (duplicate code).
This adds an <input type="password" /> which is represented by an instance of Zend\Form\Element\Password. When rendering it uses view helper Zend\Form\View\Helper\FormPassword.
adds an <input type="password" /> which is represented by an instance of Zend\Form\Element. When rendering it uses view helper Zend\Form\View\Helper\FormInput.
Because there are 2 ways to create an <input type="password" /> and 2 different classes and 2 different view helpers are used for each way, whenever there is a bug in a form element it possibly needs fixing in 2 places like in #2613 and #7171.
Ideally when adding an element to Zend\Form the check should also include checking the attributes array for a type key. With that check an <input type="password" /> will always be represented by an instance of Zend\Form\Element\Password and as a consequence will always be rendered by Zend\Form\View\Helper\FormPassword.
This also applies to all other types of <input />, but to explain the issue I only used <input type="password" /> here.
Comment
User: @jaapio
Created On: 2015-01-31T10:31:32Z
Updated At: 2015-01-31T10:31:32Z
Body
In some cases this could be useful. For example custom elements without a viewhelper could be rendered as a default element. But still have different behavior inside the element class.
Comment
User: @Martin-P
Created On: 2015-01-31T11:43:35Z
Updated At: 2015-01-31T11:43:35Z
Body
I can see the use for Zend\Form\Element, but as far as I can see now it would be better to declare it as an abstract class and only use instances of Zend\Form\Element\* for the predefined elements.
This issue has been moved from the
zendframework
repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.htmlOriginal Issue: https://api.github.com/repos/zendframework/zendframework/issues/7172 User: @Martin-P Created On: 2015-01-31T00:36:54Z Updated At: 2015-11-06T20:07:59Z Body I think there should be some refactoring of adding elements to
Zend\Form
, because inputs can be represented by different classes (duplicate code).This adds an
<input type="password" />
which is represented by an instance ofZend\Form\Element\Password
. When rendering it uses view helperZend\Form\View\Helper\FormPassword
.However this code:
adds an
<input type="password" />
which is represented by an instance ofZend\Form\Element
. When rendering it uses view helperZend\Form\View\Helper\FormInput
.Because there are 2 ways to create an
<input type="password" />
and 2 different classes and 2 different view helpers are used for each way, whenever there is a bug in a form element it possibly needs fixing in 2 places like in #2613 and #7171.In
Zend\Form\Factory
line 108 there is a check for thetype
key:Ideally when adding an element to
Zend\Form
the check should also include checking the attributes array for atype
key. With that check an<input type="password" />
will always be represented by an instance ofZend\Form\Element\Password
and as a consequence will always be rendered byZend\Form\View\Helper\FormPassword
.This also applies to all other types of
<input />
, but to explain the issue I only used<input type="password" />
here.Comment
User: @jaapio Created On: 2015-01-31T10:31:32Z Updated At: 2015-01-31T10:31:32Z Body In some cases this could be useful. For example custom elements without a viewhelper could be rendered as a default element. But still have different behavior inside the element class.
Comment
User: @Martin-P Created On: 2015-01-31T11:43:35Z Updated At: 2015-01-31T11:43:35Z Body I can see the use for
Zend\Form\Element
, but as far as I can see now it would be better to declare it as an abstract class and only use instances ofZend\Form\Element\*
for the predefined elements.