Hi all. I have a form with CI validation that uses arrays as input names. The view initially has this code:
<input type=“text” name=“urls[]”
value=”<?php echo set_value(‘urls[]’, ‘’); ?>” >
which when loaded into the browser translates correctly to this:
<input type=“text” name=“urls[]” value=”“>
Then through Jquery the user may add more identical <input>‘s to the DOM before submitting, so in the end what is POSTed could be e.g.
<input type=“text” name=“urls[]” value=”“>
<input type=“text” name=“urls[]” value=”“>
<input type=“text” name=“urls[]” value=”“>
If the submitted data passes validation, all is fine and gets stored in DB. But if validation fails, the controller sends back to the form view but I don’t see the N <input>‘s of the POSTed form. I only see one and it’s empty, which is understandable because I don’t supply a 2nd argument to set_values(), but then again what was expected was to see the inputs be re-populated through the $this->input->post(urls) array with the POSTed data that was invalid.
I do verify at the controller that $this->input->post(‘urls’) has the POSTed content (invalid or not) just fine.
I’ve read the CI user guide docs on using validation with arrays as field names
Any ideas on what’s the correct use of set_value()? By correct I mean that on validation failure, I get the N inputs that were POSTed, correctly re-populated one by one.
TIA.