CodeIgniter Forums
Dynamic Form Input Boxes - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Dynamic Form Input Boxes (/thread-25251.html)

Dynamic Form Input Boxes - El Forum - 12-05-2009

Hi All,

I have only found this topic addressed in 2 threads in my internet searches. Neither quite addressed my issue.

I am creating a dynamic form so the name attribute has to be an array. Unfortunately the form validation kicks out the []. I have tried everything I can think of but I can not get it to run with CI. I want to take advantage of the CI validation features.
CI Code that does not work.

$username = array('id'=>'username', 'name' => username[], 'value'=>set_value('username') );

Non-code igniter works fine
$name=$key."[]"; //get "disallowd key characters err if don't define name this way $form_field = "<input ID=\"questions\" class=\"\" name=\"$name\" value=\"$field_q\" >";

Any help on this will be greatly appreciated. I am sure this is not a unique issue.

Dynamic Form Input Boxes - El Forum - 12-05-2009

wrap username[] as a string and you had the set_value wrong. No idea if that will work, i suggest using the latter code.

$username =  array('id'=>'username', 'name' => 'username[]', 'value'=>set_value('username[]') );

However i'd recommend not using the form helper (other than maybe form_open()) as it is not needed and will only further complicate things if someone else needs to edit it (someone who just knows html for example or non ci user).

<input type="text" id="username" name="username[]" value="<? echo set_value('username[]');?>" />

Dynamic Form Input Boxes - El Forum - 12-07-2009

Thanks a million for your reply. I couldn't find the link that covers this topic in the user guide. I would have posted a response sooner, but I wanted to do some testing so I could post a complete reply for others who maybe interested. I still have not had time to complete the testing, so more later. Thanks again.