[!WebLoginPE? &type=`taconite`!] Add New [!eForm? &noemail=`true` &formid=`add` &eFormOnBeforeMailSent=`c4w_add` &tpl=`add` &vericode=`1` &thankyou=`3`!]
Service Description: <textarea name="description" eform="Description:description:string:#FUNCTION CheckLength($value, 200);"></textarea>
<?php
function CheckLength($value, $limit){
if (strlen($value) > $limit)
echo $value.">>".$limit;
return true;
else
echo $value.">>".$limit;
return false;
}
?>Extended Server Validation
This version instroduces extended server validation and word filtering using very flexible validation rules that can be set in the eform attribute. You can set 2 extra validation parameters, a custom error message and a validation or filter rule.
example: eform="Year of Birth:integer:1:Must be between 1950 and 2002:#RANGE 1950-2002"
The validation rules
* #LIST - comma separated list of valid values
example: #LIST blue,red,green.maroon
* #RANGE - a comma separated list of numbers or numeric ranges. When setting a range the order is not important. 1~10 or 10~1 will both validate a number between 1 and 10 (inclusive). Handles negative as well as positive numbers
example: #RANGE 1,3,-5~-15,60~82
* #SELECT - list of valid values retrieved from a database query The query should only return a single column of values (the function only checks against the first returned column). You can use the {DBASE} {PREFIX}tags which will be replaced by the MODx database name and table prefix respectively.
example: #SELECT keyword FROM {PREFIX}site_keywords
* #EVAL - string of php code. Should return either true or false
deprecatedAlthough #EVAL still works in eForm 1.4 this rule will very likely no longer be supported in future versions. Use #FUNCTION instead.
* #FUNCTION - Name of a function. The function should expect one parameter (the posted value) and return either TRUE or FALSE. See the eform event example on how you can include a function. example: #FUNCTION myValidationFunction
* #REGEX - regular expression - syntax as for preg_match() - see php manual
example: #REGEX /^[a-z]+ [a-z0-9_]+/i
* #FILTER - Filters do not validate the input but simply replace words or values using filter criteria. You can use the following filters:
o #FILTER #LIST
use double pipe to separate 2 comma separated lists of words and replacement values.
example; #FILTER #LIST badword,verybadword||goodword,verygoodword
o #FILTER #EVAL
example: #FILTER #EVAL return myFilterFunction($value);
(offcourse you have to make sure the function exists somehow)
example filter function
function myFilterFunction($value){
$badWords = array(’scribble’,’coding’);
$goodWords = array(’design’,’sleep’);
return str_replace($badWords,$goodWords,$value);
}
o #FILTER #REGEX
regular expression replace - syntax as for preg_replace() separate the search and replacement expression with a double pipe symbol (||)