commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / packages / HTML / QuickForm / Rule / Required.php
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
4 /**
5 * Required elements validation
6 *
7 * PHP versions 4 and 5
8 *
9 * LICENSE: This source file is subject to version 3.01 of the PHP license
10 * that is available through the world-wide-web at the following URI:
11 * http://www.php.net/license/3_01.txt If you did not receive a copy of
12 * the PHP License and are unable to obtain it through the web, please
13 * send a note to license@php.net so we can mail you a copy immediately.
14 *
15 * @category HTML
16 * @package HTML_QuickForm
17 * @author Bertrand Mansion <bmansion@mamasam.com>
18 * @copyright 2001-2009 The PHP Group
19 * @license http://www.php.net/license/3_01.txt PHP License 3.01
20 * @version CVS: $Id: Required.php,v 1.6 2009/04/04 21:34:04 avb Exp $
21 * @link http://pear.php.net/package/HTML_QuickForm
22 */
23
24 /**
25 * Abstract base class for QuickForm validation rules
26 */
27 require_once 'HTML/QuickForm/Rule.php';
28
29 /**
30 * Required elements validation
31 *
32 * @category HTML
33 * @package HTML_QuickForm
34 * @author Bertrand Mansion <bmansion@mamasam.com>
35 * @version Release: 3.2.11
36 * @since 3.2
37 */
38 class HTML_QuickForm_Rule_Required extends HTML_QuickForm_Rule
39 {
40 /**
41 * Checks if an element is empty
42 *
43 * @param string $value Value to check
44 * @param mixed $options Not used yet
45 * @access public
46 * @return boolean true if value is not empty
47 */
48 function validate($value, $options = null)
49 {
50 if ( is_array( $value ) ) {
51 // check if file type, if so permit empty type
52 $fileType =
53 array_key_exists( 'name', $value ) &&
54 array_key_exists( 'tmp_name', $value );
55 // hack to fix required issue with advcheckbox, but in general if any value is present then
56 // it should pass required check
57 $return = false;
58 foreach ( $value as $k => $v ) {
59 // dont check type field. Safari3 Beta does not set this
60 if ( $fileType && $k == 'type' ) {
61 continue;
62 }
63 if ( ( string ) $v != '' ) {
64 $return = true;
65 }
66 }
67 return $return;
68 } else if ((string)$value == '') {
69 return false;
70 }
71 return true;
72 } // end func validate
73
74
75 function getValidationScript($options = null)
76 {
77 return array('', "{jsVar} == ''");
78 } // end func getValidationScript
79
80 } // end class HTML_QuickForm_Rule_Required
81 ?>