[solved]How to validate CForm::dropdownlist

according to input-element

i used CForm::dropdownlist

<select name="MyForm[gender]" id="MyForm_gender">

<option value="0">Gender</option>

<option value="male">Male</option>

<option value="female">Female</option>


because it always selected by default with "0" value (not empty).

how i can validate with rules?


you could use CRangeValidator


thanks for your suggestion

is there a validation that except "0" as default value.

i mean if its value is not "0", it means not empty.

Why not user the prompt element command in your dropdown list call. That way there is no value attached to default



    'prompt'=>'Please select gender:',


 	... rest of your stuff



<?php echo $form->dropDownList($model,'gender', array('0'=>'Male', '1'=>'Female'), array('prompt'=>'Please Select')); ?>

it works…

thanks angelo.

no problem. It’s nice to be on the giving end of help once in a while:D

Thanks @Angelo

You are indeed the man with a hammer today. Just like your avatar ::)

Have been struggling for a while trying to find a solution for this.

I was trying all kind of regular expressions. but all this time I just needed