[eluser]edwin87[/eluser]
Hello CI,
I have the following problem,
I want to check if a input field is empty. The function required would be an option. But i want to customize the value that is posted.
So, if i post a empty field i modify the value to -1.
A sample form.
Code:
<form>
<input type="text" name="test">
<input type="submit">
</form>
My validation to call a function that i made.
Code:
$rules['test'] = 'trim|check_null';
And my function.
I've extended the validation with MY_Validation.
Code:
function check_null($str)
{
return $_POST[$this->_current_field] = '-1';
}
When i submit the form with a filled value like 'hello world'.
The value changes succesfully to '-1'.
But when i submit without filling in the form. The form does'nt even come by the function anymore.
That's very anoying because the database has to be filled with -1 if i didn't fill in a field.
You would say that you set a default value in de database. But my database can't handle null values. And my manager want's me to check it in the script.