CodeIgniter Forums
Form Problem. CI Form_Dropdown Issue - 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: Form Problem. CI Form_Dropdown Issue (/showthread.php?tid=27409)



Form Problem. CI Form_Dropdown Issue - El Forum - 02-09-2010

[eluser]Deep Arora[/eluser]
Here's what I am doing:

In my controller:

Code:
$options = array(
                  'small'  => 'Small Shirt',
                  'med'    => 'Medium Shirt',
                  'large'   => 'Large Shirt',
                  'xlarge' => 'Extra Large Shirt'
                );

$form_field_category = "category|Link Category|dropdown|small|" . $options;
$view_fields = array(form_field_category);
create_form($view_fields, 'form_path', 'form_name', 'perm_add');

So, I have created an array of values to be set for a dropdown form field in controller. Then I call create_form function from helper.

Inside this function:

Code:
$form_field = explode("|", $value);
if ($form_field[4]): $field_value = $form_field[4];
else : $field_value = set_value($form_field[0]);
endif;

since I have passed the VALUE field (as $options) from my controller, the form_field[4] should now have that array.

Then while I generate the form field in the same function as;

Code:
$my_form = $my_form . "<div>". form_dropdown($form_field[4], $form_field[4]);

..it gives an error

Code:
Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: helpers/form_helper.php

Line Number: 310

I tried printing the array in form_filed[4] and all it prints is the word ARRAY.

What could be wrong?


Form Problem. CI Form_Dropdown Issue - El Forum - 02-10-2010

[eluser]Valdis Ozols[/eluser]
After this
Code:
$form_field_category = "category|Link Category|dropdown|small|" . $options;
there is no array object in $form_field_category - just plain text what You got when convert array to string.