views:

55

answers:

1

About to create a form using Zend Form, all the form elements should have a checkbox before it, and depending on the state of checkbox the element is submitted(if checkbox clicked it will be submitted othervice not)

[x] Label [-------------]
[x] Label [-------------]

and the confusing part is how to deal with it using the zend form. The thing comes to my mind is to create a custom decorator , but have a feeling it won't really help. 2 -create a custom form element(will have to look at creating custom elements=)), anyway I would appreciate any help

+1  A: 

If I understand correctly, what you are looking for is a compound element and indeed you will have to use a custom decorator or form helper for this. This is somewhat difficult to explain in a few lines, thus I'm pointing you to some articles to shed some light:

I don't think it will be possible to have them not submit when the checkbox is empty though, because that's not how forms work in HTML in general. You'd either have to remove them with JavaScript when the onSubmit event is triggered, e.g. the submit button is clicked or check on the server-side if the checkbox is checked and then process the text input accordingly.

Gordon