Problem Using Arrays as Field Names (Form Validation) |
[eluser]EEssam[/eluser]
Hello, I'm using Form Validation, however, I'm not getting my fields repopulated with the correct details, I'm getting the fields populated with "Array" word. My View: Code: <input type="text" name="colors[]" value="<?= set_value('colors[]') ?>" size="3" /> My Controller: Code: $this->form_validation->set_rules('colors[]', 'Colors', 'required'); What is wrong? Please help. Thanks.
[eluser]xwero[/eluser]
try Code: <input type="text" name="colors[0]" value="<?= set_value('colors[0]') ?>" size="3" />
[eluser]Unknown[/eluser]
I can't seem to get this to work either. Tried using the method of using an index number in the field name, but still no luck. Any other suggestions?
[eluser]RS71[/eluser]
try doing something like Code: $values_array = $this->input->post('colors'); note that there isn't any brackets in colors. there might be a simpler way but I think that works (also I'm not sure if you have to have a validation rule to use $this->input->post(). ) I'm having problems with this myself
[eluser]RS71[/eluser]
Actually, I have a question of my own concerning this: I have a bunch of drop downs set as an array. When I want to repopulate the data, it sees the array instead and turns the original drop down to a multi select. How can I make it so that I can set_value of a certain key of the array or something? Code: <?php echo form_dropdown($field, $options, set_value($field, (isset($databasevalue->fetch)) ? $databasevalue->fetch : ''), $params); ?>
[eluser]Creative Stasis[/eluser]
RS71 - Try to keep on topic here. You'll have better luck posting your own thread for that question or researching to see if it's been answered before. I also am having the issue of the set_value populating as "ARRAY". Does anyone have a solution for this?
[eluser]kandmcreative[/eluser]
I am having the same issue with using arrays as field names in Form Validation. It seems that this documentation [Form Validation : Using Arrays as Field Names] is flawed. My workaround is to just use the $_POST array, but I can't access the error messages which defeats the purpose of the validation. Is anyone else having this issue?
[eluser]kandmcreative[/eluser]
This was my solution: I rewrote the set_value function and put it in MY_form_validation.php to not overwrite the official version. It never worked as written in the documentation. I think this solves the issue and matches the documentation version. Code: function set_value($field = '', $default = '') |
Welcome Guest, Not a member yet? Register Sign In |