Zend Framework - Add new input element using javascript
Asked Answered
R

2

6

I'm working on a project using Zend Framework.

I'm creating a form on which users can add a set of elements by pressing a + sign.

Zend framework uses subforms and decorators to get array of values from a form.

These will show when the page is displayed

How does the new fields created with Javascript integrate in that model?

Roux answered 12/4, 2011 at 8:19 Comment(0)
P
5

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.

Pain answered 12/4, 2011 at 19:4 Comment(5)
That is a very nice and concrete exemple :) Thanks!Roux
@DavidWeinraub above link is not working :). So, is there any updated link of this ?Saraann
@Saraann Strangely, Jeremy's site is misbehaving on the www prefix. I'll change the link and alert him.Pain
@DavidWeinraub Thanks for the help and please update once it is done.Saraann
@DavidWeinraub Thanks i tried this but this is quite old and didn't worked for me. If you can please look into my updated question and can provide me the solution that will be highly appreciated #52490966Saraann
H
2

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.

Howund answered 12/4, 2011 at 10:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.