2 // Copyright (C) 2009 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // These functions will be used to globally validate and prepare
10 // data for sql database insertion.
13 // Main function that will manage POST, GET, and
15 function formData($name, $type='P', $isTrim=false) {
17 $s = isset($_POST[$name]) ?
$_POST[$name] : '';
18 else if ($type == 'G')
19 $s = isset($_GET[$name]) ?
$_GET[$name] : '';
21 $s = isset($_REQUEST[$name]) ?
$_REQUEST[$name] : '';
23 return formDataCore($s,$isTrim);
26 // Core function that will be called by formData.
27 // Note it can also be called directly if preparing
28 // normal variables (not GET,POST, or REQUEST)
29 function formDataCore($s, $isTrim=false) {
31 if ($isTrim) {$s = trim($s);}
32 //strip slashes if magic quotes turned on
33 if (get_magic_quotes_gpc()) {$s = stripslashes($s);}
34 //prepare for safe mysql insertion
35 $s = mysql_real_escape_string($s);
39 // This function is only being kept to support
40 // previous functionality. If you want to trim
41 // variables, this should be done using above
43 function formTrim($s) {
44 return formDataCore($s,true);