[TYPO3-project-formidable] Added new options for the STANDARD validator

Luc Muller l.mul-nospam-ler at ameos.com
Thu Jun 28 17:45:31 CEST 2007


Yep

there are already some numeric validators,
but those only validates one field. If I rememberwell, the validation are 
the sames
but it only validate the field value against a pattern

like field_value > int or range_start < field_value < range_end

I think Jerome won't have too much defficulties to include your stuffs with 
those validators.

Thanks a lot for sharing :)

Luc

"Manuel Rego Casasnovas" <mrego at igalia.com> a écrit dans le message de news: 
mailman.4200.1183045035.4800.typo3-project-formidable at lists.netfielders.de...
>
> Hi,
>
> I agree with Luc, I think about a NUMERIC validator. I think that this
> is the better option.
>
> I'm glad that you add to FORMidable my littles contributions, thanks :-) .
>
> Best regards,
>    Rego
>
> -- 
> Manuel Rego Casasnovas
> Computer Science Engineer
> mailto:mrego at igalia.com
> Tel: +34 986 10 76 10
> Fax: +34 981 91 39 49
> Igalia - http://www.igalia.com
>
>
> Luc Muller escribió:
>> I've already think about this point...
>>
>> this is my reflection...
>> is pretty cool to be able to compare two fields together...
>> but, in a STANDARD validator, it do not make sense...
>> you can't compare one textfield less or more equal than another
>> but you can compare more than a DATE.
>>
>> bassically I think it should be a NUMERIC validator
>> but for a date it's hard to think about validating numeric stuff
>>
>> so... in my relfection, this validator, shouldn't be in STANDARD one
>>
>> but should be either in DATE validator, because dates are INT
>> AND
>> in numeric.
>>
>> in this way we could compare a textfiled filed with an int, to another
>> textfield filed with an int thus with a numeric validator.
>>
>> A think this is making sense ? isn't it ?
>>
>> Luc
>> "Jerome Schneider" <j.schneider at ameos.com> a ?crit dans le message de 
>> news:
>> mailman.1.1183040906.8446.typo3-project-formidable at lists.netfielders.de...
>>
>>> Hello Manuel,
>>>
>>> This is great job :)
>>> I would prefer to create a new validator:DATE to include these, but it
>>> might be better to let it in STANDARD, as it can compare more than 
>>> dates,
>>> right ?
>>>
>>> What do you think ?
>>>
>>>
>>> Manuel Rego Casasnovas a ?crit :
>>>
>>>> Hello everyone,
>>>>
>>>> I've developed four new options for the STANDARD validator, this 
>>>> options
>>>> are lessthan, lessequalthan, morethan and moreequalthan (like the 
>>>> sameas
>>>> option).
>>>>
>>>> I use this options to validate data fields, the initial date must be
>>>> less than the final date. For example:
>>>>         <renderlet:DATE name="initial_date">
>>>>             <validators>
>>>>                 <validator:STANDARD>
>>>>                     <required message="Initial date is required" />
>>>>                     <lessequalthan value="final_date" message="Initial
>>>> date greater than final date" />
>>>>                 </validator:STANDARD>
>>>>             </validators>
>>>>         </renderlet:DATE>
>>>>         <renderlet:DATE name="final_date">
>>>>             <validators>
>>>>                 <validator:STANDARD>
>>>>                     <required message="Final date is required" />
>>>>                 </validator:STANDARD>
>>>>             </validators>
>>>>         </renderlet:DATE>
>>>>
>>>> I modified the _doTheMagic function in the class
>>>> formidable_mainvalidator. I've added the next lines:
>>>>             if($this->oForm->_navConf("/lessthan", $aConf) !== FALSE) {
>>>>
>>>>                 $lessthan =
>>>> trim($this->oForm->_navConf("/lessthan/value/", $aConf));
>>>>
>>>>                 $this->oForm->_debug(null, "VALIDATOR[" .
>>>> $aInfos["TYPE"] . "][lessthan '" . $lessthan . "'] on '" . $sName . "',
>>>> TYPE [" . $aElement["type"] . "]");
>>>>                 // le champ doit ?tre identique ? un autre champ
>>>>                 // on v?rifie
>>>>
>>>>                 $oLessRdt = $this->oForm->aORenderlets[$lessthan];
>>>>                $lessvalue = $oLessRdt->_flatten(
>>>>                     $this->oForm->oDataHandler->_getThisFormData(
>>>>                         $oLessRdt->_getName()
>>>>                     )
>>>>                 );
>>>>                if(!$this->_isLessThan($value, $lessvalue)) {
>>>>                     $message =
>>>> $this->oForm->_getLLLabel($this->oForm->_navConf("/lessthan/message/",
>>>> $aConf));
>>>>                     $this->oForm->_declareValidationError($sName,
>>>> "STANDARD:lessthan", $message);
>>>>                 }
>>>>             }
>>>>            if($this->oForm->_navConf("/lessequalthan", $aConf) !== 
>>>> FALSE)
>>>> {
>>>>
>>>>                 $lessequalthan =
>>>> trim($this->oForm->_navConf("/lessequalthan/value/", $aConf));
>>>>
>>>>                 $this->oForm->_debug(null, "VALIDATOR[" .
>>>> $aInfos["TYPE"] . "][lessequalthan '" . $lessequalthan . "'] on '" .
>>>> $sName . "', TYPE [" . $aElement["type"] . "]");
>>>>                 // le champ doit ?tre identique ? un autre champ
>>>>                 // on v?rifie
>>>>
>>>>                 $oLessEqualRdt =
>>>> $this->oForm->aORenderlets[$lessequalthan];
>>>>                $lessequalvalue = $oLessEqualRdt->_flatten(
>>>>                     $this->oForm->oDataHandler->_getThisFormData(
>>>>                         $oLessEqualRdt->_getName()
>>>>                     )
>>>>                 );
>>>>                $value = $oLessEqualRdt->_flatten($value);
>>>>                if(!$this->_isLessEqualThan($value, $lessequalvalue)) {
>>>>                     $message =
>>>> $this->oForm->_getLLLabel($this->oForm->_navConf("/lessequalthan/message/",
>>>> $aConf));
>>>>                     $this->oForm->_declareValidationError($sName,
>>>> "STANDARD:lessequalthan", $message);
>>>>                 }
>>>>             }
>>>>            if($this->oForm->_navConf("/greaterthan", $aConf) !== FALSE) 
>>>> {
>>>>
>>>>                 $greaterthan =
>>>> trim($this->oForm->_navConf("/greaterthan/value/", $aConf));
>>>>
>>>>                 $this->oForm->_debug(null, "VALIDATOR[" .
>>>> $aInfos["TYPE"] . "][greaterthan '" . $greaterthan . "'] on '" . $sName
>>>> . "', TYPE [" . $aElement["type"] . "]");
>>>>                 // le champ doit ?tre identique ? un autre champ
>>>>                 // on v?rifie
>>>>
>>>>                 $oGreaterRdt = 
>>>> $this->oForm->aORenderlets[$greaterthan];
>>>>                $greatervalue = $oGreaterRdt->_flatten(
>>>>                     $this->oForm->oDataHandler->_getThisFormData(
>>>>                         $oGreaterRdt->_getName()
>>>>                     )
>>>>                 );
>>>>                if(!$this->_isGreaterThan($value, $greatervalue)) {
>>>>                     $message =
>>>> $this->oForm->_getLLLabel($this->oForm->_navConf("/greaterthan/message/",
>>>> $aConf));
>>>>                     $this->oForm->_declareValidationError($sName,
>>>> "STANDARD:greaterthan", $message);
>>>>                 }
>>>>             }
>>>>            if($this->oForm->_navConf("/greaterequalthan", $aConf) !==
>>>> FALSE) {
>>>>
>>>>                 $greaterequalthan =
>>>> trim($this->oForm->_navConf("/greaterequalthan/value/", $aConf));
>>>>
>>>>                 $this->oForm->_debug(null, "VALIDATOR[" .
>>>> $aInfos["TYPE"] . "][greaterequalthan '" . $greaterequalthan . "'] on 
>>>> '"
>>>> . $sName . "', TYPE [" . $aElement["type"] . "]");
>>>>                 // le champ doit ?tre identique ? un autre champ
>>>>                 // on v?rifie
>>>>
>>>>                 $oGreaterEqualRdt =
>>>> $this->oForm->aORenderlets[$greaterequalthan];
>>>>                $greaterequalvalue = $oGreaterEqualRdt->_flatten(
>>>>                     $this->oForm->oDataHandler->_getThisFormData(
>>>>                         $oGreaterEqualRdt->_getName()
>>>>                     )
>>>>                 );
>>>>                if(!$this->_isGreaterEqualThan($value,
>>>> $greaterequalvalue)) {
>>>>                     $message =
>>>> $this->oForm->_getLLLabel($this->oForm->_navConf("/greaterequalthan/message/",
>>>> $aConf));
>>>>                     $this->oForm->_declareValidationError($sName,
>>>> "STANDARD:greaterequalthan", $message);
>>>>                 }
>>>>             }
>>>>
>>>>
>>>> And I've added the next functions:
>>>>         function _isLessThan($value1, $value2) {
>>>>             return ($value1 < $value2);
>>>>         }
>>>>        function _isLessEqualThan($value1, $value2) {
>>>>             return ($value1 <= $value2);
>>>>         }
>>>>        function _isGreaterThan($value1, $value2) {
>>>>             return ($value1 > $value2);
>>>>         }
>>>>        function _isGreaterEqualThan($value1, $value2) {
>>>>             return ($value1 >= $value2);
>>>>         }
>>>>
>>>>
>>>> On the other hand I've made calls to the _flatten function (not the
>>>> _unFlatten), and I've needed change the two calls to the _unFlatten
>>>> function for the _flatten function. The lines:
>>>> http://test.kunstvaerker.dk/html/classformidable__mainvalidator.html#l00017
>>>> http://test.kunstvaerker.dk/html/classformidable__mainvalidator.html#l00069
>>>>
>>>> I think that you can add this new options to the next FORMidable 
>>>> release.
>>>>
>>>> Best regards,
>>>>    Rego
>>>>
>>>>
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> TYPO3-project-formidable mailing list
>> TYPO3-project-formidable at lists.netfielders.de
>> http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-project-formidable 




More information about the TYPO3-project-formidable mailing list