Php – How to use Form Collection in Zend Framework 2

PHPzend-formzend-framework2

Hi there i want to create a dynamic functionality like creating dynamic form in zend Framework
Please see the attached image.

Desire functionality

here Mapping is like One Team has more than one Multimedia.
– on Add More Multimedia Button click add Fresh block of Team multimedia
– On Click of delete link remove the Team multimedia Block
– on Click of save button save the all Block Data.

can any body suggest me how can i create this kind of functionality in zend framework 2 using Form Collection ?

here is the code for TeamMultimediaModel


class TeamMultimediaModel extends \Standard\Model\Model {
    private $team_multimedia_id;
    private $team_id;    
    private $title;
    private $link;
    private $description;
    private $type;
    private $status;
    private $created_by;
    private $created_at;
    private $last_updated_by;
    private $last_updated_at;
}

Best Answer

Have a look at this:

http://www.michaelgallego.fr/blog/2012/07/04/new-zendform-features-explained/

It explains quite well how to use the collections, also with a small example of addding javascript to add extra items on the fly

$this->add(array(
        'type' => 'Zend\Form\Element\Collection',
        'name' => 'categories',
        'options' => array(
            'label' => 'Please choose categories for this product',
            'count' => 2,
            'should_create_template' => true,
            'template_placeholder' => '__placeholder__',
            'target_element' => array(
                'type' => 'Application\Form\CategoryFieldset'
            )
        )
    ));