Can I make a textField 'required' in only one view?

I have a textfield which is required under some circumstances but not always. I would like to use the yii error checking on the field. However, making it required in the model means it will always be required. Is it possible to somehow just make it required in a single view?

<?php echo CHtml::label('Instructions', 'comment'); ?>

<?php echo $form->textField($tsession,'comment',array('size'=>45,'maxlength'=>300)); ?>

<?php echo $form->error($tsession,'comment'); ?>

I would like to do something like add an option ‘required’=>true but that isn’t working. Is there a way to do this?


look this article

Looks like you’re looking for scenarios.

this too

Thanks guys! The Scenarios option seems to be exactly what I’m after.