Empty variables after form validation fails

Hi,

I have a form with two input text fields:


<input id="ModelName_test_0" name="ModelName[test][0]" type="text">

<input id="ModelName_test_1" name="ModelName[test][1]" type="text">

Now, when I submit the form I see the values in the POST request. However, when the form submit fails then I can not get the values back into the input fields. Printing the model it shows that there are no values for $test; - is this because $test is an array in the form?

Any pointers in the right direction would be helpful :)

What I want to achieve is:

If the validation fails put the entered values back into the appropriate input text fields.

Thanks,

jrn

http://www.yiiframework.com/doc/guide/1.1/en/form.table

This chapter of the Yii guide doesn’t answer the question. Even if the title is “Collecting Tabular Input”, in fact it only deals with multiple models instances. It’s very different from having a model attribute whose value is an array.

If you want the fields to display their content and error messages, the Yii way is to use CActiveForm::textField() wich is a wrapper on CForm::activeTextField(). Unfortunately, these methods can’t deal with values of type array. For instance, they make a single call to CHtml::activeInputField() which prints a single input field.

I believe you have to handle the display with custom PHP code that adds error classes and inserts the values of the properties, etc.

Thanks for pointing this out :)

[/size]

[/color]Yes, this is what I will end up doing now :)