Welcome Guest, Not a member yet? Register   Sign In
Form Validation with Array
#1

[eluser]Unknown[/eluser]
I'm trying to use Form Validation Class using array text-field.

By the way, user manual says:
Quote:* Using Arrays as Field Names

Or to re-populate the field you would use:

Code:
<input type="text" name="options[]" value="<?php echo set_value('options[]'); ?>" size="50" />
(http://ellislab.com/codeigniter/user-gui...ysasfields)

But "set_value" returns array when it was given array as field name.
So i think that the sample doesn't work correctly.

It will output:
Code:
<input type="text" name="options[]" value="Array"...

Is this a manual's mistake?
#2

[eluser]gigas10[/eluser]
I have noticed this problem as well, but I have developed a work around.
At the top of my page I fill up my array:
Code:
$pull_vals = array();
if(set_value('pull_reason')):
    foreach(set_value('pull_reason') AS $row):
        $pull_vals[] = $row;
    endforeach;
endif;

Then to repopulate, I pass in the filled up array of values as a parameter of form_dropdown.

Code:
<tr class="even">
    <th>Pull Reason: </th>
    <td>&lt;?=form_dropdown('pull_reason[]', $pull_reason_dd, $pull_vals, $multiple);?&gt;</td>
</tr>

An official fix for this would be nice.
#3

[eluser]Unknown[/eluser]
Thank you for your reply.

I attempted to fix "system/library/Form_Validation.php" below.
Code:
<
<         return $this->_field_data[$field]['postdata'];
---
>
>         if (!is_array($this->_field_data[$field]['postdata']))
>             return $this->_field_data[$field]['postdata'];
>         else
>             return array_shift($this->_field_data[$field]['postdata']);

Then, it works as well as the manual.
Code:
&lt;input type="text" name="options[]" value="&lt;?php echo set_value('options[]'); ?&gt;" size="50" /&gt;

However, it is impossible to use "valid_email" rule.
Because empty text-fields is regarded as invalid email addresses.

Well...




Theme © iAndrew 2016 - Forum software by © MyBB