CodeIgniter Forums
Re-population with set_select() and arrays as field names - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Re-population with set_select() and arrays as field names (/showthread.php?tid=37671)



Re-population with set_select() and arrays as field names - El Forum - 01-17-2011

[eluser]Bas Vermeulen[/eluser]
Hello, I'm kinda stuck with getting re-population working when I use arrays as field names for my dropdows. I'm working on a tool to update my menu's, the tool displays the menu items in a table with a row for each menu item. The table has some columns to set the attributes for the menu items, like name, type, url, etc. I want to be able to update all menu items with one save button so I use arrays as field names:

Menu item 1: name[], type[], url[]
Menu item 2: name[], type[], url[]

For the name and url fields I use normal text inputs. That didn't work out of the box with the current form validation library, but the following update from CI Reactor fixed that https://bitbucket.org/ellislab/codeigniter-reactor/changeset/19fc3732e593

Now I'm struggling to get that working for the dropdowns aswell.

I use the following code in my view:

Code:
<select name="type[]">
    &lt;?php foreach($types as $row): ?&gt;
        &lt;?php if($row['value'] == $menu['type']): ?&gt;
            <option name="type[]" id="type[]" value="&lt;?=$row['value']?&gt;" &lt;?php echo set_select('type[]', $row['value'], TRUE); ?&gt;>&lt;?=lang($row['name'])?&gt;</option>
        &lt;?php else: ?&gt;
            <option name="type[]" id="type[]" value="&lt;?=$row['value']?&gt;" &lt;?php echo set_select('type[]', $row['value']); ?&gt;>&lt;?=lang($row['name'])?&gt;</option>
        &lt;?php endif; ?&gt;
    &lt;?php endforeach; ?&gt;
</select>

And I use the following rule for the form validation:
Code:
$this->form_validation->set_rules('type[]', 'lang:type', 'alpha_numeric_special|required');

The table loads fine with the correct defaults being selected. But when I change the type for one menu item, and make sure to get an error from the validation library, the re-population forces the selected type to all menu items instead of just the one I updated. Does anyone have a clue what is going on here? Is my implementation wrong or is it buggy like set_value was.

Thanks in advance for your help.


Re-population with set_select() and arrays as field names - El Forum - 01-20-2011

[eluser]Bas Vermeulen[/eluser]
Nobody experienced this problem?


Re-population with set_select() and arrays as field names - El Forum - 04-03-2011

[eluser]Bas Vermeulen[/eluser]
It was due to a bug which I finally managed to fix: https://bitbucket.org/ellislab/codeigniter-reactor/issue/107/form-validation-set_select-re-population