Yii Framework Forum: how to define CheckBoxList Rule - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

how to define CheckBoxList Rule Rate Topic: -----

#1 User is offline   evoup 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 14-July 10

Posted 18 July 2010 - 09:50 PM

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~
0

#2 User is offline   fastcrash 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 10-March 10
  • Location:South Jakarta

Posted 18 July 2010 - 10:46 PM

did you already add var and make it public in the model class?

public $platform;

0

#3 User is offline   evoup 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 14-July 10

Posted 18 July 2010 - 10:52 PM

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?
0

#4 User is offline   fastcrash 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 10-March 10
  • Location:South Jakarta

Posted 18 July 2010 - 11:01 PM

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.
0

#5 User is offline   evoup 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 14-July 10

Posted 18 July 2010 - 11:05 PM

no,not define in db.
0

#6 User is offline   fastcrash 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 10-March 10
  • Location:South Jakarta

Posted 18 July 2010 - 11:16 PM

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.

:)
0

#7 User is offline   evoup 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 14-July 10

Posted 19 July 2010 - 12:35 AM

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~ :lol:
0

#8 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 19 July 2010 - 04:46 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users