Part of the EllisLab Network
   
 
Using Arrays as Field Names - Form Validation bug?
Posted: 19 September 2009 03:47 AM   [ Ignore ]  
Summer Student
Total Posts:  2
Joined  09-19-2009

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

<input type="text" name="sth[]" value="set_value('sth[]')"

and use a rule like

$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.

Profile
 
 
Posted: 19 September 2009 09:19 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  281
Joined  02-12-2009

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.

 Signature 

.htaccess mod_rewrite no longer working when moving from the development server to production server?

Check that you have AllowOverride All in your host config file for the public web directory of your website.

AND USE THE FRACKING SEARCH!!!  it works, it really does!

Profile
 
 
Posted: 26 September 2009 04:26 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  2
Joined  09-19-2009

Thank You for help,
but even when I have the index there

<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
<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 :/

Profile
 
 
Posted: 10 December 2009 05:17 AM   [ Ignore ]   [ # 3 ]  
Grad Student
Rank
Total Posts:  42
Joined  01-21-2009

I’m having this problem as well. The user guide clearly says to use the EXACT field name, but:

<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

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

will give me ‘Array’ in the field after submitting.

Profile