Good Morning,
I know the problem, he is currently dealing with, from my asmselectex extension.
Example 1:
If you use the activeDropDownList as suggested:
<?php echo CHtml::activeDropDownList($model, $attribute, $data, $htmlOptions); ?>
the form element, may looks like this:
<select size="4" multiple="multiple" name="User[roles]" id="User_roles">
<option value="user">User</option>
<option value="manager">Manager</option>
</select>
but the submitted data, will look like this:
Array
(
[User] => Array
(
[roles] => manager
)
)
even when the user, did select multiple options from the select form element!
Example 2:
A way to have multiple selections, would be to to append brackets to the $attribute-property:
<?php echo CHtml::activeDropDownList($model, $attribute.'[]', $data, $htmlOptions); ?>
the form element, would then look like this:
<select size="4" multiple="multiple" name="User[][roles]" id="User_roles">
<option value="user">User</option>
<option value="manager">Manager</option>
</select>
but the submitted data, will look like this:
Array
(
[User] => Array
(
[0] => Array
(
[roles] => user
)
[1] => Array
(
[roles] => manager
)
)
)
when the user, did select multiple options from the select form element.
Example 3:
In the case, that dotpack and me want to create
<select size="4" multiple="multiple" name="User[roles][]" id="User_roles">
<option value="user">User</option>
<option value="manager">Manager</option>
</select>
the submitted data, would be ordered in the $_POST request, like shown below
Array
(
[User] => Array
(
[roles] => Array
(
[0] => user
[1] => manager
)
)
)
Maybe there is already a way to create this case, but after looking at CHtml::resolveName, I think there isnt.
greets ironic
//edit:
there is a way to create this:
<?php
$htmlOptions['name'] = get_class($model).'['.$attribute.']'.'[]';
echo CHtml::activeDropDownList($model, $attribute, $data, $htmlOptions);
?>
This would prevent that CHtml::resolveNameID gets the name-attribute from CHtml::resolveName.