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

[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');
whenever I have to "re-populate" the form after submitting any value to such field it's value is "Array", when it should be the value I submitted there.

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.
#2

[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.
#3

[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]'); ?>">
set_value always returns nothing. I hope I don't have to set rules for every index of an array separately. And why in latest user guide there's and example of using arrays
Code:
<input type="text" name="options[]" value="<?php echo set_value('options[]'); ?>" size="50" />
- no index in set_value?


--- edit
ok, I see that this bug is already reported here, too bad it still exists :/
#4

[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" />
<input type="text" name="items[]" value="<?= set_value('items[]'); ?>" class="text" id="new-maintenance-item-2" />
<input type="text" name="items[]" value="<?= set_value('items[]'); ?>" class="text" id="new-maintenance-item-3" />

and

Code:
array('field' => 'items[]', 'label' => 'Items', 'rules' => 'min_length[3]'),

will give me 'Array' in the field after submitting.




Theme © iAndrew 2016 - Forum software by © MyBB