0

I have a PHP form that need to submit a array of numbers, what we have in view:

<input type="text" id="ProductForm_sizeobj_1" name="ProductForm[sizeobj[1]]" value="13">
<input type="text" id="ProductForm_sizeobj_2" name="ProductForm[sizeobj[2]]" value="13">
<input type="text" id="ProductForm_sizeobj_3" name="ProductForm[sizeobj[3]]" value="13">

And I define in form class:

public $sizeobj = array();

public function rules() {
    return array(
        array('/** other attributes **/, sizeobj', 'safe')
    );
}

Since "Sizeobj" is a dynamic attribute and the size will growth more then 3, therefore I use array. However after form submitted the error throw as follow:

Failed to set unsafe attribute "sizeobj[1" of "ProductForm".

I believe I might using the wrong method to setup array attribute, or wrong rule, any advice? I'm new to Yii, any help is appreciated.

Ju Chu
  • 55
  • 3
  • 8
  • 1
    http://stackoverflow.com/questions/1978664/is-it-possible-to-have-double-nested-input-tag-arrays-in-html – Andreas Apr 07 '14 at 10:52

1 Answers1

2

Use name="ProductForm[sizeobj][1]" instead of name="ProductForm[sizeobj[1]]"

Andrii Mishchenko
  • 2,626
  • 21
  • 19