[TYPO3-project-formidable] Added new options for the STANDARD validator
Manuel Rego Casasnovas
mrego at igalia.com
Tue Jun 19 13:45:41 CEST 2007
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
--
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
More information about the TYPO3-project-formidable
mailing list