Welcome Guest, Not a member yet? Register   Sign In
form_input with id as an arrays and form_prep
#1

[eluser]Unknown[/eluser]
It's easiest if I explain this by putting everything useful in a view:
Code:
<?php
        $this->load->helper('form');
        $conf   =       Array(
                0       =>      array(
                        'description'   =>      '14" Ladder'
                ),
                1       =>      array(
                        'description'   =>      '14" Ladder',
                ),
        );
        
        foreach ( $conf as $line )
        {
                $desc   =       $line['description'];
                echo form_input("description[]", $desc, 'class="span1"') . "<br/>\n";
        }
?&gt;
The above code produces two input fields on the page, the first of which contains the pre-filled text 14" Ladder. The second contains the text 14.

If I replace the input-as-array part with individual fields:
Code:
$count = 0;
        foreach ( $conf as $line )
        {
                $desc   =       $line['description'];
                echo form_input("description$count", $desc, 'class="span1"') . "<br/>\n";
                $count  +=      1;
        }
Then all the text is pre-filled correctly.

If I attempt to form_prep the $desc value manually with description[], it produces some messy results both in the front end and the saving back end.

Is this actually a bug? I had a hard time searching for the best way of describing this, so it's more than likely I missed something (there were older posts about form_prep and quot for example). The code does work, so long as the form_input isn't an array.

For the moment I think the best work around is to manually form_prep the data and not use form_input for this field, but if I could get it working properly that would be so much cleaner.

Edit: Sorry, CodeIgniter 2.1.2, apache web services on both a FreeBSD server and an Debian server.




Theme © iAndrew 2016 - Forum software by © MyBB