2

Consider the case of an online CV.

There will be a row containing a few input text for each education line and each experience line.

I want to group each field in an education line and and an experience line in a subform.

Then the total of those lines will be also grouped in education and experience.

The idea is to have a 3 dimensional array which would look like this:

[experience][0][company]
[experience][0][from]
[experience][0][current]
[experience][1][company]
[experience][1][from]
[experience][1][until]

[education][0][institution]
[education][0][from]
[education][0][until]
[education][0][graduated]

I've read a lot about subforms with zend framework. I haven't been able to understand where I can tell that an input element belongs to a subform.

What I get so far is this:

public function init()
{
    $this->setMethod('post');

    $this->addElement('text', 'CvName', array(
        'label'     =>'CV Name:',
        'required'  => true,
        'validator' => 'alnum'
    ));

    $this->addElement('text', 'UserID', array(
        'label'     =>'UserID:',
        'required'  => true,
        'validator' => 'alnum'
    )); //I'm still just testing so userid is a field 

    //Now I want the experience fields here
    $this->addSubForm('experience');

    //How do I tell my element 'Company' that it belongs to the subform 'experience'?
    $this->addElement('text', 'Company', array(
        'label'     =>'Company:',
        'required'  => true,
        'validator' => 'alnum'
    ));

    $this->addElement('submit', 'submit', array(
        'ignore'    => true,
        'label'     => 'Save CV'
    ));
}

How do I tell my element 'Company' that it belongs to the subform 'experience'?

Also, should I use addSubForm or addSubForms?

4

0 回答 0