| 3 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
|
|
5 |
* File: validate_transform.makeDate.php
|
|
|
6 |
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
|
|
7 |
*
|
|
|
8 |
* This library is free software; you can redistribute it and/or
|
|
|
9 |
* modify it under the terms of the GNU Lesser General Public
|
|
|
10 |
* License as published by the Free Software Foundation; either
|
|
|
11 |
* version 2.1 of the License, or (at your option) any later version.
|
|
|
12 |
*
|
|
|
13 |
* This library is distributed in the hope that it will be useful,
|
|
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
16 |
* Lesser General Public License for more details.
|
|
|
17 |
*
|
|
|
18 |
* You should have received a copy of the GNU Lesser General Public
|
|
|
19 |
* License along with this library; if not, write to the Free Software
|
|
|
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
21 |
*
|
|
|
22 |
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
|
|
23 |
* @copyright 2001-2005 New Digital Group, Inc.
|
|
|
24 |
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
|
|
25 |
* @package SmartyValidate
|
|
|
26 |
*/
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* transform fuction, make a date out of three other form fields
|
|
|
30 |
*
|
|
|
31 |
* @param string $value the value of the field being transformed
|
|
|
32 |
* @param array $params the parameters passed to the transform function
|
|
|
33 |
* @param array $formvars the form variables
|
|
|
34 |
*/
|
|
|
35 |
|
|
|
36 |
function smarty_validate_transform_makeDate($value, $params, &$formvars) {
|
|
|
37 |
|
|
|
38 |
if(!empty($params['date_fields'])) {
|
|
|
39 |
list($_year, $_month, $_day) = preg_split('![\s,]+!',$params['date_fields']);
|
|
|
40 |
} elseif(!empty($params['field2']) && !empty($params['field3']) && !empty($params['field4'])) {
|
|
|
41 |
$_year = $params['field2'];
|
|
|
42 |
$_month = $params['field3'];
|
|
|
43 |
$_day = $params['field4'];
|
|
|
44 |
} else {
|
|
|
45 |
$_year = $params['field'] . 'Year';
|
|
|
46 |
$_month = $params['field'] . 'Month';
|
|
|
47 |
$_day = $params['field'] . 'Day';
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
if(!isset($formvars[$_year]) || strlen($formvars[$_year]) == 0) {
|
|
|
51 |
trigger_error("SmartyValidate: [makeDate] form field '$_year' is empty.");
|
|
|
52 |
return $value;
|
|
|
53 |
} elseif(!isset($formvars[$_month]) || strlen($formvars[$_month]) == 0) {
|
|
|
54 |
trigger_error("SmartyValidate: [makeDate] form field '$_month' is empty.");
|
|
|
55 |
return $value;
|
|
|
56 |
} elseif(!isset($formvars[$_day]) || strlen($formvars[$_day]) == 0) {
|
|
|
57 |
trigger_error("SmartyValidate: [makeDate] form field '$_day' is empty.");
|
|
|
58 |
return $value;
|
|
|
59 |
} else {
|
|
|
60 |
return $formvars[$_year] . '-' . $formvars[$_month] . '-' . $formvars[$_day];
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
?>
|