[solved] AR Model form and custom fields

I have an activerecord model form, it contains inputs like

CHtml::activeTextField($myModel, 'modelField')

Now I want to add a couple of custom non-model fields (to process their content later in controller).

I created custom public property in model and tried

CHtml::activeTextField($myModel, 'customField')

but the value of this field is lost when validation fails.

CHtml::textField also loses the entered value.

How can I do it?

You also need to override safeAttributes() and list those extra attributes there.

Thanks, that worked!

how to add custom non-model fields (public $field) in $model->attributes ???


(in AR)

public $duracao_aula;

public $qtd_tempos;

(in Controller)

$horario_aula->attributes = $_POST['horario_aula'];

when use:

CVarDumper::dump($horario_aula->attributes , 5, true) ;

the custom fields(duracao_aula and qtd_tempos) not exist in attributes array.


this custom fields are validating and in form show validate error after submit.


I do this in AR:

the fields 'duracao_aula' and 'qtd_tempos' was joined with the fields of the table in safeAttributes();

 public function safeAttributes()


        return 'id_segmento,id_serie,inicio,fim,turno,tipo,duracao_aula,qtd_tempos';