Using Arrays as Field Names - Form Validation bug? |
[eluser]Unknown[/eluser]
Hello, I`m working on my first app with CI, and got a problem with using arrays in forms and validating it with form_validation - I`m doing everything just how user guide tells to do, so I believe it's a bug. The problem is that when I have an array input like Code: <input type="text" name="sth[]" value="set_value('sth[]')"> and use a rule like Code: $this->form_validation->set_rules('sth[]', 'Something', 'required'); Problem existed in previous 1.7.1 version, and still exists in latest 1.7.2 I hope it's me who's doing something wrong, it's quite urgent for me, so big thanks for any support.
[eluser]brianw1975[/eluser]
it's doing exactly as it should. you need to put in a key name or number to access a certain value in the array. for example use set_value('sth[0]') in your first input with sth[] for the name.
[eluser]Unknown[/eluser]
Thank You for help, but even when I have the index there Code: <input type="text" name="sth[]" value="<?= set_value('sth[0]'); ?>"> Code: <input type="text" name="options[]" value="<?php echo set_value('options[]'); ?>" size="50" /> --- edit ok, I see that this bug is already reported here, too bad it still exists :/
[eluser]sheldonnbbaker[/eluser]
I'm having this problem as well. The user guide clearly says to use the EXACT field name, but: Code: <input type="text" name="items[]" value="<?= set_value('items[]'); ?>" class="text" id="new-maintenance-item-1" /> and Code: array('field' => 'items[]', 'label' => 'Items', 'rules' => 'min_length[3]'), will give me 'Array' in the field after submitting. |
Welcome Guest, Not a member yet? Register Sign In |