root/trunk/patForms/Rule/URL.php

Revision 271, 1.4 kB (checked in by argh, 3 years ago)

Fixed bug #172: modified behavior of the setValue for the set element so that you may pass either a string for a single selected value, or an array with a list of selected entries; fixed bug #173 in patForms_Rule_URL: translated missing french strings.

Line 
1 <?php
2 /**
3  * patForms Rule URL
4  *
5  * $Id$
6  *
7  * @package        patForms
8  * @subpackage    Rules
9  */
10
11 /**
12  * patForms Rule URL
13  *
14  * @package        patForms
15  * @subpackage    Rules
16  * @author        Stephan Schmidt <schst@php-tools.net>
17  * @license        LGPL, see license.txt for details
18  * @link        http://www.php-tools.net
19  */
20 class patForms_Rule_URL extends patForms_Rule
21 {
22    /**
23     * name of the rule
24     *
25     * @abstract
26     * @access    private
27     */
28     var    $ruleName = 'URL';
29
30    /**
31     * define error codes and messages for the rule
32     *
33     * @access    private
34     * @var        array    $validatorErrorCodes
35     * @todo     translate error messages
36     */
37     var    $validatorErrorCodes  =   array(
38         "C"   =>   array(
39              1   =>   "The URL has an invalid syntax.",
40         ),
41         "de" =>    array(
42             1    =>    "Die URL hat ein ungültiges Format.",
43         ),
44         "fr"=>    array(
45              1   =>   "L'URL a une syntaxe incorrecte.",
46         ),
47     );
48
49    /**
50     * method called by patForms or any patForms_Element to validate the
51     * element or the form.
52     *
53     * @access    public
54     * @param    object patForms    form object
55     */
56     function applyRule(&$element, $type = PATFORMS_RULE_BEFORE_VALIDATION)
57     {
58         $value = $element->getValue();
59         if (empty($value)) {
60             return true;
61         }
62         $ereg = "(http|ftp|https)://[-A-Za-z0-9._]+(\/([A-Za-z0-9\-\_\.\!\~\*\'\(\)\%\?]+))*/?";
63         if (!eregi($ereg, $value)) {
64             $this->addValidationError(1);
65             return false;
66         }
67         return true;
68     }
69 }
70 ?>
Note: See TracBrowser for help on using the browser.