Question

I added three new fields to my model (year, month, date). When I submit the form data isn't get populated. All those three custom attributes are null on submission.

I have asked this question before on implementing multiple fields for single property and I did what the answer suggested. What should I do. Here is my code.

User model:

class User extends CActiveRecord
{
    public $month;
    public $year;
    public $day;
    ...

View file:

<?php echo $form->labelEx($model, "dob"); ?>
<?php echo $form->dropDownList($model, 'year', $model->getDobOptions('year')); ?>
<?php echo $form->dropDownList($model, 'month', $model->getDobOptions('month')); ?>
<?php echo $form->dropDownList($model, 'day', $model->getDobOptions('day')); ?>
Was it helpful?

Solution

Did you remember to set those fields as safe as well?

public function rules() {
    return array(
        array('month, year, day', 'safe'),
    ...

If you do not, this does not 'copy' the values over from the form to the model in the controller:

$model->attributes = $_GET['User'];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top