support for standardization of input and mysql string preparation
[openemr.git] / library / formdata.inc.php
blobf8103ee60974855c04b6f714cd3dae4967ad2337
1 <?php
2 // Copyright (C) 2009 Rod Roark <rod@sunsetsystems.com>
3 //
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.
8 //
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
14 // REQUEST variables
15 function formData($name, $type='P', $isTrim=false) {
16 if ($type == 'P')
17 $s = isset($_POST[$name]) ? $_POST[$name] : '';
18 else if ($type == 'G')
19 $s = isset($_GET[$name]) ? $_GET[$name] : '';
20 else
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) {
30 //trim if selected
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);
36 return $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
42 // functions.
43 function formTrim($s) {
44 return formDataCore($s,true);