CodeIgniter Forums
an array as input in form_input - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: an array as input in form_input (/showthread.php?tid=32632)



an array as input in form_input - El Forum - 07-29-2010

[eluser]jtan[/eluser]
I plan to have several text field in the form, is it possible to have an array on the form_input?


an array as input in form_input - El Forum - 07-29-2010

[eluser]ELRafael[/eluser]
Short answer : YES :lol:

View file
Code:
<?php foreach ( $itens->result() as $i ) : ?>
  <input type="checkbox" name="ids[]" value="<?php echo $i->id; ?>" />
<?php endforeach; ?>

Controller file
Code:
$id = $this->input->post('ids', TRUE);
foreach ( $ids as $id )
{
  //Do something with $id
}



an array as input in form_input - El Forum - 07-29-2010

[eluser]jtan[/eluser]
can I make spreadsheet like thing with several form_input and use array to have several variables?


an array as input in form_input - El Forum - 07-29-2010

[eluser]ELRafael[/eluser]
Sorry but I didn't get.

Try to put some examples, maybe I can help you.


an array as input in form_input - El Forum - 07-29-2010

[eluser]jtan[/eluser]
like i wanted to make a spreadsheet out of using several form input fields then each fields represent an element in the array

variable[x][y]

where X is column and Y is row

i won't have memory hog problem having 64 x 120 array?


an array as input in form_input - El Forum - 07-29-2010

[eluser]ELRafael[/eluser]
Yes, you can.

Code:
<input type="checkbox" name="ids[][]" value="<?php echo $i->id; ?>" />

Look the name="ids[][]"

If you do a
Code:
var_dump($this->input->post('ids'));
you'll see your array.

The memory can be a problem. Depends how you write your code, in special the loop section.