Problem validating array form fields - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Problem validating array form fields (/showthread.php?tid=23787) |
Problem validating array form fields - El Forum - 10-21-2009 [eluser]logan2z[/eluser] I've got a form to which I dynamically add some input fields based on user interaction. These input fields all contain a URL string. Initially, I was naming these fields url[0], url[1], ... and adding a validation rule to a group in my form_validation.php file that looked like this: array('field' => 'url[]', 'label' => "Price", 'rules' => 'callback_url_check' ) This didn't seem to work as I had expected. So I renamed my input fields to url_0, url_1, ... and dynamically added validation rules in my controller like this: foreach ($url) { $this->form_validation->set_rules($url, 'URL', 'callback_url_check'); } before invoking the validator. I want the callback to set an error message for the field if validation fails but, according to the validator docs, the call to set_error_message in a callback should look like this: $this->form_validation->set_message('url_check', 'Invalid URL'); But if I've attached the callback to multiple fields, how does the set_message() function know which one to associate the message with? Is it not valid to share the callback function with multiple form fields? Obviously what I'm doing isn't working correctly or I wouldn't be posting this :-) I'm pretty new to CI so I'm probably missing something obvious here... Problem validating array form fields - El Forum - 10-21-2009 [eluser]imn.codeartist[/eluser] you need to modify code form_validation class and here is the nice example how to do that check this thread http://ellislab.com/forums/viewthread/45589/ Problem validating array form fields - El Forum - 10-21-2009 [eluser]logan2z[/eluser] So the only way to do this is to modify the framework!? Ugh. Are array fields supposed to work? The docs say they do, but I couldn't make it happen with a callback. Problem validating array form fields - El Forum - 10-21-2009 [eluser]imn.codeartist[/eluser] array fields validation works basically probably you have done some mistakes or missed something please check them once again or post your code here |