evoup
(Evoex)
July 19, 2010, 2:50am
1
i use follow code define a checkbox list
echo CHtml::CheckBoxList('platform[]',null,array(0=>"1",1=>"2"));
and in the model,i wrote this
public function rules()
{
return array(
array('platform','required')
);
}
but i doesn`t work,tell me "xxx.platform" not defined!
how should i set the require rule,help~
xicath
(Xicath)
July 19, 2010, 3:46am
2
did you already add var and make it public in the model class?
public $platform;
evoup
(Evoex)
July 19, 2010, 3:52am
3
ok.it has gone!
but after i submit, stile show the erro summary
platform can not be empty.I`ve check the item already,anyone know why?
xicath
(Xicath)
July 19, 2010, 4:01am
4
you could use print_r() before save to see the data send via $_POST.
sory, i forget to ask you, did you defined ‘platform’ in database table as field?
if so, my previous post is not require.
xicath
(Xicath)
July 19, 2010, 4:16am
6
platform can not be empty.I`ve check the item already,anyone know why?
its because you define it in rules as required
public function rules()
{
return array(
array('platform','required')
);
}
my suggest just print_r the $_POST data.
print_r($_POST['table_name'])
put this on actonCreate or actionUpdate in your controler.
if still not resolve, you could show your code.
evoup
(Evoex)
July 19, 2010, 5:35am
7
thks, i do it in this way ,made a hidden textfield name platform,and set the hidden textfield required,when check the checkbox,assign the value to the hidden textfield, but i think this is a stupid method,but anyway i can go on~
zaccaria
(Matteo Falsitta)
July 19, 2010, 9:46am
8
If you set "required" for a checkbox, the user will be requred to check it.
Use:
public function rules()
{
return array(
array('platform','safe')
);
}
‘safe’ will make the SetAttribute to collect the user input, but the textfield will not be requred.