activeDropDownList with the options selected correctly when posted


If I have a many to many relationship and use the following form field:

<?php echo CHtml::activeDropDownList($postModel, 'tags', Tag::model()->findAll(), array('multiple'=>true)); ?>

The options are selected correctly when I load the form for editing.

But if I change the selection and post the form with an error, the field is loaded again with the data already recorded, instead of the new selection.

If the post is to create and return with an error, the dropdown always back empty.

The framework does not automatically deal with this issue. What is the correct way to fix this?

Looks like ‘tags’ attribute is not safe in rules(). Check you have a rule for this attribute.


‘tags’ is a relation and only now i learned that the relation also can/should be cited in the rules.

Thank you!