Hi Matthew

I wanted to know if this is a known issue, or an expected behaviour (or neither?!)

I'm creating a form composed of a subform and a submit element. The idea is to create a long list of skills that are returned in array notation so I can more easily aggregate the results and store in a database. So the subform works well for this. However I also wanted to use the display group feature within the subform to group sub- categories together to make the form more readable. The expected output should be:-

<form enctype="application/x-www-form-urlencoded" action="" method="post">
    <dl class="zend_form">
        <dt></dt>
        <dd>
            <fieldset id="category6">
                <legend>3d Design</legend>
                <dl>
<dt><label for="skill-39" class="optional">Architecture</label></dt> <dd><input type="checkbox" name="skill[39]" id="skill-39" value="1"></dd> <dt><label for="skill-38" class="optional">Environmental design</label></dt> <dd><input type="checkbox" name="skill[38]" id="skill-38" value="1"></dd>
                </dl>
            </fieldset>
            <fieldset id="category7">
                <legend>Brand experience</legend>
                <dl>
<dt><label for="skill-42" class="optional">Architecture</label></dt> <dd><input type="checkbox" name="skill[42]" id="skill-42" value="1"></dd> <dt><label for="skill-43" class="optional">Environmental design</label></dt> <dd><input type="checkbox" name="skill[43]" id="skill-43" value="1"></dd>
                </dl>
            </fieldset>
...etc...

However if I try and add the $this->addDisplayGroup() method to logically group these categories, all my elements are losing their array notation and are simply named with their id. Snippet:-
            <fieldset id="category6">
                <legend>3d Design</legend>
                <dl>
<dt><label for="39" class="optional">Architecture</label></dt> <dd><input type="checkbox" name="39" id="39" value="1"></dd> <dt><label for="38" class="optional">Environmental design</label></dt> <dd><input type="checkbox" name="38" id="38" value="1"></dd>
                </dl>
            </fieldset>
...etc...
If I disable that line, the elements are named correctly but I lose my fieldset groupings. Here's my form code example as a reference:-

class My_Form_AccountSkills extends Zend_Form
{
    public function init()
    {
        $this->addSubForm(new My_Form_AccountSkillsSubform(), 'skill');

        $submit = new Zend_Form_Element_Submit('login');
        $submit->class = 'formsubmit';
        $submit->setValue('Login')
               ->setDecorators(array(
                   array('ViewHelper', array('helper' => 'formSubmit'))
               ));

        $this->addElements(array(
            $submit
        ));
    }
}

class My_Form_AccountSkillsSubform extends Zend_Form_SubForm
{
    public function init()
    {
        $skillModel = new My_Skill_Category();
        $skills = array();
        $elements = array();

        // Loads categories and skills from a database
        foreach ($skillModel->fetchAll() as $skill) {
            $key = 'category' . $skill->id;
            $skills = array();
            foreach ($skill->findMy_Skill_List() as $list) {
                $checkbox = new Zend_Form_Element_Checkbox($list->id);
                $checkbox->setLabel($list->name);
                $skills[] = $list->id;
                $this->addElement($checkbox);
            }
$this->addDisplayGroup($skills, $key, array('legend' => $skill->name));
        }
    }
}

Is this a bug or something that needs to be solved with alternative/ custom decorators? I can pop this into JIRA if it is a bug, however.

Cheers

--

Simon Mundy | Director | PEPTOLAB

""" " "" """""" "" "" """"""" " "" """"" " """"" "  """""" "" "

202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000
Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654 4124
http://www.peptolab.com

Reply via email to