Welcome Guest, Not a member yet? Register   Sign In
Trouble with callback and default parameter
#6

[eluser]CroNiX[/eluser]
The first parameter passed to a validation callback function is always the VALUE that that form control sent. In this case the value of the email field, which will not be a boolean FALSE. So $only_identity can't be FALSE which is why this isn't working.

You can only manually pass a parameter to the callback function if you use the square brackets and pass it in there, which will be sent as the 2nd parameter to your callback. This is always a string.

Send the string 'false' as a 2nd parameter to the callback function:
Code:
$this->form_validation->set_rules('email', 'Email', 'trim|required|callback__validate_credentials[false]|valid_email|xss_clean');

Receive the 2nd parameter in the callback function:
Code:
function _validate_credentials($field_value, $only_identity='true')
{
  if ($only_identity == 'false')
  {
     //the parameter was set and it was false
  }
  else
  {
     //the parameter was not set, so it must be true
  }
And to use the same callback without sending the 2nd parameter, just remove the brackets, and $only_identity will be considered 'true':
Code:
$this->form_validation->set_rules('email', 'Email', 'trim|required|callback__validate_credentials|valid_email|xss_clean');


Messages In This Thread
Trouble with callback and default parameter - by El Forum - 10-25-2012, 06:36 AM
Trouble with callback and default parameter - by El Forum - 10-25-2012, 06:47 AM
Trouble with callback and default parameter - by El Forum - 10-25-2012, 06:55 AM
Trouble with callback and default parameter - by El Forum - 10-25-2012, 07:23 AM
Trouble with callback and default parameter - by El Forum - 10-25-2012, 08:07 AM
Trouble with callback and default parameter - by El Forum - 10-25-2012, 08:42 AM
Trouble with callback and default parameter - by El Forum - 10-25-2012, 10:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB