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">
These input fields get generated with the following commands:
<?php echo $form->textField($model,'test[0]'); ?>
<?php echo $form->textField($model,'test[1]'); ?>
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?
Even after the validation all values are still assigned to the variables:
if($model->validate()) {
echo "<pre>";
print_r($_POST);
return;
}
This returns:
[ModelName] => Array
(
[test] => Array
(
[0] => myFirstInputField
[1] => mySecondInputField
)
)
So the values are in the POST but after the failed validation they are gone and I get empty variables:
[ModelName] => Array
(
[test] =>
)
The variable test is declared safe in the validation rules.
What I want to achieve is:
If the validation fails put the entered values back into the appropriate input text fields.
Any pointers in the right direction would be helpful :)