Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

handling of default values in input

  • Loading branch information...
commit 0615d8607edcfc6a69320917ffafc250daa27a4a 1 parent 9fea65c
@jarnix authored
View
6 library/php/classes/Nf/Front.php
@@ -167,7 +167,7 @@ public function findRoute() {
if(file_exists($filename)) {
require_once($filename);
-
+
if(isset($_routes)) {
for($i=count($_routes)-1; $i>=0; $i--){
@@ -180,8 +180,8 @@ public function findRoute() {
$requestType=$route[0][0];
}
switch($requestType) {
- case 'default':
-
+ case 'default':
+
// tester si match, sinon on continue jusqu'à ce qu'on trouve
if(preg_match('#^' . $route[0] . '#', $uri, $result)) {
// on teste la présence du module controller action indiqué dans la route
View
31 library/php/classes/Nf/Input.php
@@ -16,6 +16,7 @@ class Input
const F_STRING='string';
const F_TRIM='trim';
const F_URL='url';
+ const F_STRIPTAGS='stripTags';
const V_INTEGER='int';
const V_NATURAL='natural';
@@ -38,6 +39,7 @@ class Input
const V_URL='url';
const V_DEFAULT='default';
+
private $_params=array();
private $_filters=array();
private $_validators=array();
@@ -209,6 +211,11 @@ private function metaFilterAndValidate($metaAction) {
}
// add the validator to the validators for this field
if($metaAction=='validate') {
+ // special case of the default value
+ if($optionName==self::V_DEFAULT) {
+ $this->_fields[$paramName]['value']=$ret;
+ $ret=true;
+ }
$isValid=$isValid && $ret;
$validators[$optionName]=$ret;
}
@@ -255,7 +262,7 @@ private function setField($paramName, $value=false, $isValid=null, $validators=n
public function __get($paramName) {
return $this->_fields[$paramName]['value'];
}
-
+
public function __isset($paramName) {
return isset($this->_fields[$paramName]['value']);
}
@@ -302,6 +309,19 @@ public static function filterNumeric($value) {
return filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
}
+ public static function filterStripTags($value) {
+ $containsTags=true;
+ $out=$value;
+ while($containsTags) {
+ $out2=strip_tags($out);
+ if($out2==$out) {
+ $containTags=false;
+ }
+ $out=$out2;
+ }
+ return $out;
+ }
+
public static function filterRegexp($value, $regexp) {
return preg_replace($regexp, '', $value);
}
@@ -347,7 +367,7 @@ public static function validateBase64($value) {
}
public static function validateNumeric($value) {
- return ($this->filterNumeric($value)==$value);
+ return (self::filterNumeric($value)==$value);
}
public static function validateEquals($value, $check) {
@@ -404,4 +424,11 @@ public static function validateUrl($value) {
return false;
}
+ public static function validateDefault($value, $defaultValue) {
+ if(empty($value)) {
+ return $defaultValue;
+ }
+ return $value;
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.