Zend Form - dynamic adding subforms

冷暖自知 提交于 2019-12-08 07:46:45

问题


I'm working with Zend Form and I need to dynamically (when filling out the form by user) add groups of elements. For example I have form with few fields describing offer and one subform to set offer price. But offer can have more than one price and price is not only 1 element, its composed of

  1. offer regular price
  2. offer discount price
  3. offer items count

So there are 3 different elements in one gruop.

I can create elements with javascript but when should I add them to Zend Form Object?


回答1:


you could make each of the groupings a subform that way when you add via javascript, you could ajax that portion of the form in by just rending the subform with a 'Belongsto'. Then, you could read in your post when it comes back to you and do a foreach on it and add the elements back that way.

check out http://www.stephenrhoades.com/?p=364

Otherwise, in your ajax to get the form markup, you could be building a form object that you could save to the session, that way it will already be built at posting time.



来源:https://stackoverflow.com/questions/6831145/zend-form-dynamic-adding-subforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!