I'm working on a application where users can be placed in a group. The groups can be added/edited in the database so these are dynamic. I've got the following form:
public function init()
{
$this->setMethod('post')
->setAttrib('id', 'userGroup');
//get the stuff out of the db
$group = new Application_Model_GroupMapper();
$disciplines = $group->fetchAll(array(
'type' => 'discipline',
'orderby' => 'g.name',
'sort' => 'ASC'
));
$disciplineFields = array();
foreach($disciplines as $row):
$el = $row->name;
$this->addElement('checkbox', $el, array(
'required' => false,
'label' => $el,
'class' => 'inputCheckbox'
));
$this->$el->setCheckedValue('true');
$this->$el->setUnCheckedValue('false');
array_push($disciplineFields,$el);
endforeach;
//discipline information
$this->addDisplayGroup(
$disciplineFields,
'disciplineInformation',
array('legend' => 'Discipline')
);
BUT I get the error:
No valid elements specified for display group
Well that's strange because when i count my array $disciplineFields it has 4 items and the fields are echoed when I'm removing the displayGroup line. Also when I modify the displayGroup line to
//discipline information
$this->addDisplayGroup(
array('Schipper'), //this is one of the records in the database
'disciplineInformation',
array('legend' => 'Discipline')
);
The 'Schipper' field is showed in the fieldset/displayGroup.
Why is this not working? What am I doing wrong?
You should put a breakpoint on Zend_Form::addDisplayGroup and debug it. I see nothing wrong in your code, perhaps your data are not correctly retrieved.
If you make a Zend_Debug::dump
on disciplines
, what is displayed ?
And you should pass your discipline via a setDisciplines method of your form instead of hard code it in the init.