![]() |
Extending Form validation - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Extending Form validation (/showthread.php?tid=13164) |
Extending Form validation - El Forum - 11-13-2008 [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> 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) 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. Extending Form validation - El Forum - 11-13-2008 [eluser]edwin87[/eluser] You will always see that when you post it on the forum you found out the solution. And yes finally! ![]() The form validator, doesn't do callback functions if the field is empty. Only if you add the check required after your callback function. Code: $rules['test'] = "check_null|required|integer|trim"; Extending Form validation - El Forum - 11-13-2008 [eluser]drewbee[/eluser] [quote author="edwin87" date="1226594349"]You will always see that when you post it on the forum you found out the solution. And yes finally! ![]() The form validator, doesn't do callback functions if the field is empty. Only if you add the check required after your callback function. Code: $rules['test'] = "check_null|required|integer|trim"; That isn't true in 1.7 ![]() |