Hello,
I’m writing a registration form and I’ve just added a couple of radio buttons to let the user decide to agree or not with the privacy policy that will be added later.
Thought it could be useful for others so here is the code
controller:
$model=new User;
$model->setScenario('register');
...
view:
<div class="frm_center">
<?php $test =array("yes"=>"Yes", "no"=>"No"); ?>
<?php echo CHtml::activeRadioButtonList($model,'do_agree', $test, array("separator"=>" ")); ?>
</div>
model:
public function rules()
{
return array(
// ... (other rules) ...
array('do_agree', 'required', 'on'=>'register'),
array('do_agree', 'compare', 'compareValue'=>'yes',
'message'=>'You must agree!', 'on'=>'register'),
);
}
public function safeAttributes() {
$base =parent::safeAttributes();
$base[]="conf_pass"; // (you may have to change or comment this)
return array(
$base,
'register'=>array_merge($base, array('do_agree')),
);
}