Zend Form Mastery with Zend Config - Part 2 Core Form Configuration
Today we move on in learning how to configure the basics of Zend Forms, such as action, method, enctype, accept, accept-charset et al with Zend Config XML. It couldn’t be simpler.
Ok, this should have been part one, but irrespective, here’s the second installment in zend form mastery with zend config - core form configuration. As the W3c Form spec says, there are 8 attributes applicable to forms. These are:
- action - what the form will do when submitted
- method - the method of submission, usually GET or POST
- enctype - the language encoding of the content that is submitted
- accept - a csv list of content types that the script processing the form will accept
- name - the name of the form in the DOM hierarchy
- onsubmit - what will be done on submit
- onreset - what will be done on reset
- accept-charset - character encodings accepted by the script processing this form on submission
There are also id, class, dir, style, title, target and a series of intrinsic events. So how do we use a Zend Config XML file to set all these properties? Well, it’s pretty straight-forward to do, hence why this part in the series should have come first, not second.
Let’s have a look at a slightly modified version of the XML snippet from the first part of the series below:
Here we have the outline of one form, called radios. It has three properties already set: action, method and name. When we pass our Zend_Config_Xml object, configured with that, we’re going to get a form that is configured as below
That’s all well and good, but what about all the other elements? Gladly it’s pretty straight-forward. Below is the full XML configuration required to configure each form attribute that we need.
From this configuration, we’ll get a form that renders like the image below:
The html of the form will be as below:
Grab the Code
In a hurry? Grab a compressed copy of the code from Github.com. It’s a module that you can drop straight in to an existing Zend Framework project, ready to use.
You might also be interested in...
- Zend Form Mastery with Zend Config – Part 3 Standard Form & Element Options
- Zend Form Mastery with Zend Config - Part 1 Custom Filter Paths
- Zend Form Mastery with Zend Config – Part 4 Configuring Zend Validators
- Simplify Form Validation and Reuse, Use Validation Groups
- Beginning cloud development with cloudControl – Part 4 – Memcache
comments powered by Disqus