Zend Framework - adding a new input element using javascript

I am working on a project using the Zend Framework.

I am creating a form on which users can add a set of elements by clicking the + sign.

The Zend framework uses subforms and decorators to get an array of values ​​from the form.

They will be displayed when the page is displayed.

How are new fields created using Javascript in this model created?

+5
source share
2 answers

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

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

The result of the technique is to add / call the preValidation() method on the form to check the message for fields that are not on the form. If he finds any such fields, they will be added to the form object. By the time isValid() and getValues() all Zend_Form_Element objects are already attached to the form, so processing is performed as usual.

+5
source

One suggestion is to define all the input fields that you want to provide using the zend form.

But when the form is displayed, you can hide certain fields and make them visible by pressing + .

I think this is the easiest approach, because to add decorators and things you will need to change the php files on the client side, and this is not possible.


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

+2
source

Source: https://habr.com/ru/post/888406/


All Articles