How can I in ZF2 create custom form element with custom validator? I want to create custom category picker that uses jQuery and content of this element should be rendered from phtml script. In ZF1 it was quite easy but in ZF2 I don't know from where to start.
标签:
zend-framework2
相关问题
- Why does recursive submodule update from github fa
- How to pass options/params to formCollection field
- Compress html output from zend framework 2
- zend smtp mail crashes after 100+ mails
- 404 HTTP errors not being rendered in JSON using Z
相关文章
- Zend Framework 2 Forms Array notation for drop dow
- Use spiffy navigation with zfcrbac module
- Best practice to call another controller action fr
- How to use Zend Service Amazon?
- Difference between init() and onBootStrap() in Zen
- Does Zend Framework 2.0 leave out the amazon s3 li
- Zend Framework 2 Flash Messenger returning no mess
- doctrine migrations 2 + zend framework 2 = is it p
A form element must implement a
Zend\Form\ElementInterface
. A default class is theZend\Form\Element
which you can use as a base form:CUSTOM VALIDATOR
You can let the element directly assign a custom validator. Then you must implement the
Zend\InputFilter\InputProviderInterface
:CUSTOM RENDERING
At this moment it is a bit complex how Zend Framework handles the rendering of custom form element types. Usually, it just returns plain
<input type="text">
elements.There is one option, then you have to override the
Zend\Form\View\Helper\FormElement
helper. It is registered asformelement
and you must override this view helper in your custom module:Furthermore, every form element in Zend Framework 2 is rendered by a view helper. So you create a view helper for your own element, which will render the element's content.
Then you have to create your own form element helper (
MyModule\Form\View\Helper\FormElement
):As a last step, create your view helper to render this specific form element:
If you want to render a .phtml file for example for this form element, load it inside this helper:
It will render a
my-module/form-element/foo.phtml
and in this script you will have a variable$element
which contains your specific form element.