This recipe involves different ways of creating forms, and after that we will talk about how elements are added to the form. In the last part of this recipe we will discuss how to validate forms, and the best way of accomplishing this.
A basic ZF2 skeleton application, with at least one module where we can work in, is necessary to create and output forms.
If we want to use form annotations, we also require Doctrine\Common
to be initiated in the skeleton as it has the parsing engine to parse the annotations. If we are using composer (which comes with the Zend Framework 2 skeleton) we can simply update our composer.json
by adding the following line to the required section:
"doctrine/common": ">=2.1",
Tip
Make sure the comma on the end of the line is only there when there are still lines beneath it. If there are no lines coming after this line except for a closing brace, please refrain from adding the comma as it will fail the process.
Next is to run the composer...