Dear all,
has just started out Yii web app and encountered this problem.
What i am trying to achieve:
-To display a form with different panels with tags that can be selected from each category, however the user only need to choose one tag from any category
-user can select some items from panel 1, some from panel 2, etc and then click submit button to process.
Problem:
The validation is performed only for the first group (image in attachment):
In the image attached, the error should not happen because at least one checkbox is checked. However if i choose one the checkboxes from the first panel, the validation works well, ignoring the checkboxes from the second panel.
Basically, i want to display at least two checkboxLists that represent data from the same group. I also have problems with data submission because only the the last checkboxList is considered:
Some code from my _form.php:
(...)
foreach($arrayCategories as $key => $value){
?>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="heading<?= $key ?>">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse<?= $key ?>" aria-expanded="true" aria-controls="collapse<?= $key ?>">
<?= $value ?>
</a>
</h4>
</div>
<div id="collapse<?= $key ?>" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="heading<?= $key ?>">
<div class="panel-body">
<?php
$arrayTags = Tags::find()->where(['id_category'=>$key])->all();
$arrayOpt = [];
foreach($arrayTags as $valueTags){
$arrayOpt[$valueTags->id_tag] = $valueTags->getTagsHasLanguages($valueTags->id_tag)[0]->name;
}
echo $form->field($modelExperienceTags[0], "id_tag[]")->checkboxList($arrayOpt);
?>
(...)
By some reason, yii2 cannot handle form elements with the same name. Can anyone give me a solution to this problem?
Thanks