06-27-2008, 09:34 PM
|
#1 (permalink)
|
|
The Acquainted
Join Date: May 2008
Posts: 175
Thanks: 9
|
automatically clean form posted variables.
I use this as a simple cleanup of posted variables (I only do post automatically), as well as a nice trim to the data. This is nice because even if an array is given, it will follow it...
This is a basic piece of my Form class. This form class is simply the superclass to all of my sub-classes. There is more stuff I use within this as well, but you get the idea with this I think.
only strip_slashes() if you have the lovely magic quotes on.
This does pass by ref as well, so you can throw anything you want into it and it modifies the original variable without returning anything.
PHP Code:
<?php class Form extends Page { var $isPostBack; function Form() { $this->isPostBack = count($_POST) > 0 ? true : false; if ($this->isPostBack) { array_walk_recursive($_POST, array($this,'cleanGlobal')); } } function cleanGlobal(&$var, $key = null) { if(is_array($var)) { array_walk_recursive($var, array($this, 'cleanGlobal')); } else { // How do you want each variable handled? $var = trim(stripslashes(($var)); } } } ?>
__________________
There are No Stupid Questions. But there a LOT of Inquisitive Idiots.
Last edited by drewbee : 07-07-2008 at 04:29 PM.
Reason: wow formating ftw...
|
|
|