Welcome Guest, Not a member yet? Register   Sign In
Dynamic Form Input Boxes
#1

[eluser]noCodeMonkeys[/eluser]
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.
#2

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

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

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

http://ellislab.com/codeigniter/user-gui...ysasfields
#3

[eluser]noCodeMonkeys[/eluser]
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.




Theme © iAndrew 2016 - Forum software by © MyBB