Yii Framework Forum: FormModel validation failes for multiselect fields - Yii Framework Forum

Jump to content

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

FormModel validation failes for multiselect fields Rate Topic: -----

#1 User is offline   neopersia 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 06-January 12

Posted 07 May 2012 - 06:36 PM

Hi,

I have a set of checkboxes that are loaded dynamically:

<?php echo CHtml::checkBoxList('facilities', $form['facilities'], $this->getAttributes('Facility'), array('separator'=>' ')); ?>


I added this rule to the form model to validate the selected values (which are supposet to be numbers):

public function rules()
{
    return array(
        array('facilities', 'numerical'),
        // the rest of the rules...
    );
}


after submitting the form I get the "Facilities must be a number" error.

what am I doing wrong?
0

#2 User is offline   Pravin Gajera 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 137
  • Joined: 25-October 11
  • Location:India

Posted 07 May 2012 - 10:49 PM

Hi


can you check what you have a get on Controller action print_r($_POST) or print_r($_GET)

I think you have receive " on " so far this error " Facilities must be a number "

Otherwise comment // array('facilities', 'numerical'),

Thanks
0

#3 User is offline   neopersia 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 06-January 12

Posted 08 May 2012 - 07:18 AM

Thanks for your answer.

the form values are sent to the server as they should. they are as well loaded into the form model as an array of checkbox values.

for a workaround I added my own validator in the model:

public function multi_int($field)
{
    $value = (array) $this->$field;
    $value = array_map('intval', $value);
    $this->$field = $value;
}


I just want to know whether Yii can already validate this kind of input values or I should use custom validators.
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