开发者

Good practice on implementing elements with the state in Zend Form

开发者 https://www.devze.com 2022-12-23 21:39 出处:网络
About to create a form开发者_StackOverflow 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

About to create a form开发者_StackOverflow 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


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:

  • Compound Elements with Zend_Form
  • The simplest Zend_Form decorator
  • From the inside-out: How to layer decorators
  • Rendering Zend_Form decorators individually
  • Creating composite elements

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号