CodeIgniter Forums
an array in name field in a form? - 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: an array in name field in a form? (/showthread.php?tid=29469)



an array in name field in a form? - El Forum - 04-10-2010

[eluser]ajsie[/eluser]
in the documentation it says that you can have an array in the name field.

Code:
<input type="text" name="options[]" value="<?php echo set_value('options[]'); ?>" size="50" />

but i dont get why u would do that. could someone explain?


an array in name field in a form? - El Forum - 04-10-2010

[eluser]InsiteFX[/eluser]
Did you read this?

Form Validation

Look towards the bottom Using Arrays as Field Names.

InsiteFX


an array in name field in a form? - El Forum - 04-11-2010

[eluser]Clifford James[/eluser]
I use an array in my forms to group data (for different database tables), like an user and settings:

Code:
<input type="text" name="user[name]" />
<input type="text" name="user[email]" />

<input type="text" name="user_settings[language]" />
<input type="text" name="user_settings[group]" />

I can now access only the user data very easily trough:
Code:
$this->input->post('user'); // array('name', => 'value', 'email' => 'value')

And the settings
Code:
$this->input->post('user_settings'); // array('language' => 'value', 'group' => 'value')



an array in name field in a form? - El Forum - 04-11-2010

[eluser]ajsie[/eluser]
thanks clifford james! that helped me to understand!