[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...