Welcome Guest, Not a member yet? Register   Sign In
Form Validation: Using Arrays as Field Names in 2.0
#1

[eluser]jarnold[/eluser]
I'm upgrading an existing application from 1.7.x to 2.0, and I see that the behavior of form validation field arrays has changed. Unfortunately, the new documentation doesn't really show how to process multiple values in your controller.

For example, my form allows the user to add new input fields via Javascript. In other words, there could be any number of these:

<input type="text" name="editor[]" value="" />

In the old days, submitting the form and calling $this->form_validation->set_value('alias[]') would give you an array you could loop through. Now, it seems set_value keeps a count and will only give you one value at a time. In my controller, how can I get all of the post values for editor[]?

I guess I could do something like this, but it's inelegant, and it doesn't account for a user who leaves a middle field blank:

Code:
do {
    $new_value = $this->form_validation->set_value('editor[]');
    if ($new_value != '') {
        $editors[] = $new_value;
    }
} while ($new_value != '');


Messages In This Thread
Form Validation: Using Arrays as Field Names in 2.0 - by El Forum - 02-03-2011, 12:03 PM
Form Validation: Using Arrays as Field Names in 2.0 - by El Forum - 02-03-2011, 01:42 PM
Form Validation: Using Arrays as Field Names in 2.0 - by El Forum - 02-25-2011, 09:40 AM
Form Validation: Using Arrays as Field Names in 2.0 - by El Forum - 02-25-2011, 11:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB