CodeIgniter Forums
Form validation with native PHP function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Form validation with native PHP function (/showthread.php?tid=40789)



Form validation with native PHP function - El Forum - 04-19-2011

[eluser]dinhtrung[/eluser]
Hi everyone,
I wonder why CI does not support some native PHP function for validation, like file_exists(), is_dir, is_readable, is_writable ?

I have a textbox for user to type in the file name or directory name, and I want to use all 4 functions above to validate the user input.

All though I set the rule correctly, but it not work.

Dive into the Form_validation class, I found that for native PHP functions like that, only post data is effects. I can only use function to change the value, like md5, base64 or strip_tags (without the 2nd param).

My Idea is, CI Form_validation should handle all this function, and 2nd parameters as well.

Any idea?


Form validation with native PHP function - El Forum - 04-19-2011

[eluser]Boris Strahija[/eluser]
Those are not functions that should be in the form validation lib. Anyway, it's easy enough to create a callback rule for what you need.


Form validation with native PHP function - El Forum - 04-19-2011

[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#preppingdata

Quote:Any native PHP function that accepts one parameter can be used as a rule, like htmlspecialchars, trim, MD5, etc.

If you need to validate with these rules, like Boris Strahija said, you can create a callback to do so.