Zend Framework - Add new input element using javascript

岁酱吖の 提交于 2019-11-28 10:22:05

The best demo of dynamically adding fields on the client to a Zend_Form with which I am familiar comes from Jeremy Kendall:

http://jeremykendall.net/2009/01/19/dynamically-adding-elements-to-zend-form/

The upshot of the technique is to add/call a preValidation() method on the form to check the post for fields missing in the form. If it finds any such fields, then they are added to the form object. By the time isValid() and getValues() are called, all the Zend_Form_Element objects have already been attached to the form, so processing runs as normal.

One suggestion would be to define all input fields that you want to provide using zend form.

But when the form is displayed you could hide certain fields and make them visible by clicking on +.

I think this is the most simple approach because for adding decorators and stuff you would need to change php files on client side and this is not possible.


Another suggestion, you could define several forms. Clicking on + redirectes the user to another form with an added field.

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