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>';
}
also i am using some javascript code here
<script>
jQuery(document).ready(function(){
// add multiple select / deselect functionality
jQuery(".parentCheck").click(function () {
var childId = jQuery(this).attr('id');
jQuery('.child_'+childId).attr('checked', this.checked);
});
});
function checkParent(parentId,childId) {
if(jQuery(".child_"+parentId).length == $(".child_"+parentId+":checked").length) {
$('#'+parentId).attr("checked", "checked");
} else {
$('#'+parentId).removeAttr("checked");
}
}
</script>
this works good for me in .phtml page but actually i want to put this code in zend form and call like this
echo $this->form ;
what i can do?
Note :- here Tagkey is :-
$tags =new Campaign_Model_DbTable_Tag();
$aResultData = $tags->getTagkey();
$this->view->Tagkey = $aResultData;
You can make sub form to each parent and child.
EG :-
!!! zend method name may be incorrect. please find the those methods. This is only way to do your work. Try with form decorators.
code of testForm.php
Why are you use onclick method in element? Try it using Jquery click function like your another code. 🙂