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.

1

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.