Welcome Guest, Not a member yet? Register   Sign In
Problem validating array form fields
#1

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


Messages In This Thread
Problem validating array form fields - by El Forum - 10-21-2009, 06:33 PM
Problem validating array form fields - by El Forum - 10-21-2009, 09:23 PM
Problem validating array form fields - by El Forum - 10-21-2009, 11:26 PM
Problem validating array form fields - by El Forum - 10-21-2009, 11:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB