DropDownList only shows 1 or 0

Hello i have a dropdownlist that is suppose to ask the user yes or no and they choose and when it saves into the database it only says 0 (yes) or 1(no)…how would i display yes or no?..

here is the snippet from the code:

<?php echo $form->DropDownList($model,‘contactFirst’,array(yes,no)); ?>

try this

<?php echo $form->DropDownList($model,'contactFirst',array('0'=>'yes','1'=>'no')); ?>

nope didn’t work did the same thing…thanks though

Hi repeater09,

I copied your code and used it as is, and it actually works fine. This is the generated HTML when I used it:

<select id="LoginForm_contactFirst" name="LoginForm[contactFirst]">

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

<option value="1">no</option>


Can you paste here the HTML generated in your browser? Have you tried other browsers?

take a look at here http://www.yiiframew…alidation-rules .

I think the original problem is about displaying a dropdownlist with yes or no as the options. What’s with the safe validation rules?

oh my bad ,actually it was mistaken by me.

a tricky way just try for fun

<?php echo $form->DropDownList($model,'contactFirst',array('yes'=>'yes','no'=>'no')); ?>

That’s okay. Probably you want to answer to a different concern and mistakenly posted your answer here.

could you please help me in this problem my problem link

hey did you solve your prob?

nothing has worked…I have it showing on the drop down list but when i attempt to look at it on the database or the view page it only shows a 1 or 0…thanks for the help guys i guess its impossible…

if i’m not wrong, your problem is how to display yes or no in your view page after you save in database and not to save in the database, right??

i don’t know it’s better way to use in yii or not but i do this in my project…

  1. in my sql, i use this

select CASE contactfirst WHEN "0" THEN "Yes" WHEN "1" THEN "No" end as contactfirst ...... from ...... where .....

2.i had function in my model to change that.

public function getContact($val){


				return "Yes";

			else if($val==1)

				return "No";



and call in your view(gridview) with this.


sorry if i misinterpret what you mean because of my bad english…

just want to help :)

Hi repeater,

I see. I misinterpreted your question. You are talking about "displaying" the values "yes" and "no", so I thought it has something to do with the view. So what you really want is to "save" the values "yes" or "no" to the database, right?

It is not impossible. And in your view, use

<?php echo $form->DropDownList($model,'contactFirst',array('yes'=>'yes','no'=>'no')); ?>

just like jayanthan.ece said. If it is still saving 0 and 1, check the column properties of the table, maybe it is set to int or something. It has to be varchar(3).