I recently published an article trying to shed some light on the Zend_Form component, in particular, when using it with Zend_Config_Ini. In the article I presented a config I developed while trying to learn Zend_Form myself, but unfortunately realized that using generic elementDecorators comes with a price.

Apparently, using elementDecorators overrides individual element level decorators. This leads to some unexpected and annoying results. For instance, in my previous example, I lose the ability to hide or even add individual attributes to specific elements. This leaves me with a form that has labels for each element including the submit button:
Zend Form Table Login with all Labels

The only way I found to correct this problem is to add decorators to each element individually. This is highly redundant and hardly ideal, but it gives the control necessary to fix this problem. It also bloats the config file significantly; previously, the config was 31 lines long, but now it is 47 lines long:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[login]
; General Form Information
login.action = "login/submit"
login.method = "post"
login.id = "login"
; Form Decorators
login.decorators.elements.decorator = "FormElements"
login.decorators.table.decorator = "HtmlTag"
login.decorators.table.options.tag = "table"
login.decorators.form.decorator = "Form"
; Username Element
login.elements.username.type = "text"
login.elements.username.options.label = "Username:"
login.elements.username.options.required = true
login.elements.username.options.validators.alnum.validator = "alnum"
login.elements.username.options.validators.regex.validator = "regex"
login.elements.username.options.validators.regex.options.pattern = "/^[a-z]/i"
login.elements.username.options.validators.strlen.validator = "StringLength"
login.elements.username.options.validators.strlen.options.min = "5"
; Username Decorators
login.elements.username.options.decorators.helper = "ViewHelper"
login.elements.username.options.decorators.tableData.decorator.td = "HtmlTag"
login.elements.username.options.decorators.tableData.options.tag = "td"
login.elements.username.options.decorators.label.decorator = "Label"
login.elements.username.options.decorators.label.options.tag = "td"
login.elements.username.options.decorators.tableRow.decorator.tr = "HtmlTag"
login.elements.username.options.decorators.tableRow.options.tag = "tr"
; Password Element
login.elements.password.type = "password"
login.elements.password.options.label = "Password:"
login.elements.password.options.required = true
login.elements.password.options.validators.strlen.validator = "StringLength"
login.elements.password.options.validators.strlen.options.min = "6"
; Password Decorators
login.elements.password.options.decorators.helper = "ViewHelper"
login.elements.password.options.decorators.tableData.decorator.td = "HtmlTag"
login.elements.password.options.decorators.tableData.options.tag = "td"
login.elements.password.options.decorators.label.decorator = "Label"
login.elements.password.options.decorators.label.options.tag = "td"
login.elements.password.options.decorators.tableRow.decorator.tr = "HtmlTag"
login.elements.password.options.decorators.tableRow.options.tag = "tr"
; Submit Form Element
login.elements.submit.type = "submit"
login.elements.submit.options.label = "Submit"
; Submit Decorators
login.elements.submit.options.decorators.helper = "ViewHelper"
login.elements.submit.options.decorators.tableData.decorator = "HtmlTag"
login.elements.submit.options.decorators.tableData.options.tag = "td"
login.elements.submit.options.decorators.label.decorator = "Label"
login.elements.submit.options.decorators.label.options.tag = "td"
login.elements.submit.options.decorators.label.options.class = "submit"
login.elements.submit.options.decorators.tableRow.decorator.tr = "HtmlTag"
login.elements.submit.options.decorators.tableRow.options.tag = "tr"

Personally, I think this is poor design and feel it may even be a bug, but I will attempt to submit it to ZF’s issue tracker and see what they say. Otherwise though, I still feel as though Zend_Form is a great component, and will continue to publish any discoveries I come across.