tags:

views:

13

answers:

0

I've created a Zend_Form with the following elements which are populated by data from a Zend_DB_Table one-to-many query. The form is being used for CRUD and my question concerns updating records.

The form looks like this:

class Application_Form_Teacher extends Zend_Form

{

 public function init()
    {

    //Set the form method, action and attributes for the display form to post

    $this->setMethod('post');
    $this->setAttrib('sitename', 'source');
    $this->setAttrib('enctype', 'multipart/form-data');
    $this->setDecorators(array(
        'FormElements',
        'Form'
    ));

    /**
     * Add firstname form element
     */

    $firstname = $this->createElement('text', 'firstname');
    $firstname->setLabel('Firstname: ')
                     ->setAttrib('size', 25)
                     ->setAttrib('autocomplete', 'off')
                     ->setAttrib('maxlength', 50)
                     ->addFilter('htmlentities')
                     ->addFilter('striptags')
                     ->addValidator('StringLength', false,array(0,60))
                     ->setValue('')
                     ->setRequired(true);

    //Set Decorators
    $firstname->setDecorators(array(
               'ViewHelper',
               'Description',
               'Errors',
               array(array('data'=>'HtmlTag'), array('tag' => 'td')),
               array('Label', array('tag' => 'td')),
               array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
           ));

    /**
     * Add lastname form element
     */

    $lastname = $this->createElement('text', 'lastname');
    $lastname->setLabel('Lastname: ')
                     ->setAttrib('size', 25)
                     ->setAttrib('autocomplete', 'off')
                     ->setAttrib('maxlength', 50)
                     ->addFilter('htmlentities')
                     ->addFilter('striptags')
                     ->addValidator('StringLength', false,array(0,60))
                     ->setValue('')
                     ->setRequired(true);

    //Set Decorators
    $lastname->setDecorators(array(
               'ViewHelper',
               'Description',
               'Errors',
               array(array('data'=>'HtmlTag'), array('tag' => 'td')),
               array('Label', array('tag' => 'td')),
               array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
           ));

    echo "$this->teacherService->getTeacherClasses($id)";

    /**
     * Create Classname Subform
     */
    $classname = new Zend_Form_Subform();
    $classname = $this->createElement('text', 'classname');
    $classname->setLabel('Classes: ')
                     ->setAttrib('size', 25)
                     ->setAttrib('autocomplete', 'off')
                     ->setAttrib('maxlength', 50)
                     ->addFilter('htmlentities')
                     ->addFilter('striptags')
                     ->addValidator('StringLength', false,array(0,60))
                     ->setValue('');

    //Set Decorators
    $classname->setDecorators(array(
               'ViewHelper',
               'Description',
               'Errors',
               array(array('data'=>'HtmlTag'), array('tag' => 'td')),
               array('Label', array('tag' => 'td')),
               array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
           ));

The Zend_Db_Table query in my Model outputs a teacher first and lastname and then a series of lessons taught by that teacher.

Using 'populate' I can get the first and lastname of the teacher to appear in the $firstname and $lastname form elements.

My question is, how do I populate the $classname element, such that each lesson taught creates and populate a new $classname element?

I need in essence the form to automatically generate a $classname element for each lesson.

Any advice on how I can achieve this would be much appreciated.