Révision 6156a9b6
Ajouté par Jocelyn Delande il y a presque 11 ans
class/FormValidator.class.php | ||
---|---|---|
58 | 58 |
} |
59 | 59 |
} |
60 | 60 |
$this->sanitized = $sanitized; |
61 |
|
|
62 |
return ($err == false); |
|
61 |
return (count($this->errors) == 0); |
|
63 | 62 |
} |
64 | 63 |
|
65 | 64 |
public function validate_field($validator, $content) { |
... | ... | |
83 | 82 |
return $this->sanitized; |
84 | 83 |
} |
85 | 84 |
|
85 |
public function print_errors() { |
|
86 |
/** raw & quick HTML errors printing, for case that shouldn't happen to users. |
|
87 |
*/ |
|
88 |
echo '<pre>'; |
|
89 |
var_dump($this->errors()); |
|
90 |
echo '</pre>'; |
|
91 |
} |
|
92 |
|
|
86 | 93 |
public static function register($name, $function) { |
87 | 94 |
self::$field_validators[$name] = $function; |
88 | 95 |
} |
... | ... | |
124 | 131 |
} |
125 | 132 |
); |
126 | 133 |
|
134 |
// Validate that it is not a file path |
|
135 |
FormValidator::register( |
|
136 |
'basename', |
|
137 |
function ($v) { |
|
138 |
if (!strpos($v, '/') && !strpos($v, '\\')) { |
|
139 |
return $v; |
|
140 |
} else { |
|
141 |
throw new FieldValidationError('est un chemin'); |
|
142 |
} |
|
143 |
} |
|
144 |
); |
|
145 |
|
|
146 |
|
|
127 | 147 |
?> |
Formats disponibles : Unified diff
some request input checking/sanitization