Welcome Guest, Not a member yet? Register   Sign In
Problem with setting a default zero in form validation rule
#1

[eluser]jprateragg[/eluser]
In my controller, I'm using this form validation rule to clean my input field:

Code:
$this->form_validation->set_rules('adjusted', 'Adjusted Value', 'trim|clean_int|default_zero');

I'm using a helper function (default_zero) to set any values to 0 if they are empty or null.

Code:
function default_zero($input) {
if($input == '' or $input == null) {
  return 0;
} else {
  return $input;
}
}

However, whenever the I try to submit an empty value, it never comes back 0. If I enter 0 into the field, a 0 gets returned. If I enter a number, that number gets returned. But when I leave the field blank, nothing gets returned when I was expecting a 0 to be returned. Is this a bug or am I not doing something right? Thanks!


Messages In This Thread
Problem with setting a default zero in form validation rule - by El Forum - 11-21-2012, 12:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB