Welcome Guest, Not a member yet? Register   Sign In
Get current input field data in callback function
#1

[eluser]JavaJunky[/eluser]
Is there a way inside a validation callback function to get the data related to the field currently being validated?

I'm trying to write one function that I can use to validate multiple fields, but I want to be able to know which field I'm validating in the callback function.

I want to do something like this:

Code:
function my_value_check($str) {
   $this_field = ??? // THE CURRENT FIELD BEING VALIDATED (can be field label)
   switch($this_field) {
      case "first_name":
         // checks $str against data for "first_name"
      ...
   }
   // return true or false
}
#2

[eluser]farinspace[/eluser]
I think you should be able to setup your rules like following:

Code:
$this->form_validation->set_rules('field', 'Field', 'trim|required|callback_my_value_check[field]');

Code:
function my_value_check($fieldValue,$fieldName) { ... }

the "field" name should come through as the second parameter ... (i think this should work)

...

Also perhaps you can extend "/system/libraries/Validation.php" ... look at line 288, that is where a callback function gets called, you can probably modify it to also pass the field name as a parameter ...
#3

[eluser]JavaJunky[/eluser]
Cool! I will try it out. Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB