I have the following php script now i want to put his script in zend forms Here is my code so far :-
$parents = array();
$childs = array();
foreach ($this->Tagkey as $aResultDataValue) {
$parents [$aResultDataValue['parent']] = $aResultDataValue['parent'];
$childs [$aResultDataValue['parent']][] = $aResultDataValue['child'];
}
foreach ($parents as $parent) {
echo '<div>';
$parent_value = "'$parent'";
echo '<div><input type="checkbox" name="parents[]" value="'.$parent.'" id="'.$parent.'" class="parentCheck"/>
<label for="parents_'.$parent.'">'.$parent.'</label></div>';
foreach ($childs[$parent] as $child) {
$child_value = "'$child'";
echo '<div style="margin-left:15px;"><input type="checkbox" name="childs[]" value="'.$child.'" id="childs_'.$child.'" class="child_'.$parent.'" onclick="checkParent('.$parent_value.','.$child_value.');"/>
<label for="childs_'.$child.'">'.$child.'</label></div>';
}
echo '</div>';
}
now i am going to use this pure php script in zend form what i am trying is here :-
class Admin_Form_Users extends Zend_Form
{
public function init()
{
$parents = array();
$childs = array();
foreach ($this->Tagkey as $result) {
$parents [$result['parent']] = $result['parent'];
$childs [$result['parent']][] = $result['child'];
}
foreach ($parents as $parent) {
$subForm = new Zend_SubForm();
$subForm->addElement($parent);
foreach ($children as $child) {
$subForm->addElement($child);
}
$form->addSubForm($subForm);
}
$parent = new Zend_Form_SubForm();
$parent->addElements(array(
new Zend_Form_Element_MultiCheckbox('subscriptions', array(
'label' =>
'Which parent would you like to subscribe to?',
'multiOptions' => $parents,
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
array('InArray',
false,
array(array_keys($parents)))
)
)),
));
$child = new Zend_Form_SubForm();
$child->addElements(array(
new Zend_Form_Element_MultiCheckbox('subscriptions', array(
'label' =>
'Which child would you like to subscribe to?',
'multiOptions' => $childs,
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
array('InArray',
false,
array(array_keys($childs)))
)
)),
));
$this->addSubForms(array(
'$child' => $child,
'parent' => $parent
));
I got an error
Warning: Invalid argument supplied for foreach() in /var/www/dashboard_campaign/application/modules/admin/forms/Users.php on line 19
means here :- foreach ($this->Tagkey as $aResultDataValue) {
Tagkey comes from database model
what i can do an I am newbie in zend framework what i am doing wrong help me
$TagKeyis not a member of Zend_Form, and I don’t see where it is being added to it.You could either pass the model that TagKey comes from into the form’s constructor, or in the form’s
init()method, you need to create an instance of the model and get the TagKey variable.Here is how you can get it from your controller into the form object.
Then add a constructor to your form.