Location: PHPKode > scripts > Combo Validation > combo-validation/documentation/index.html
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Combo validation user guide</title>

<style type="text/css">
li {
margin-bottom: 0em;
}
code {
overflow: auto;
width:100%;
}
</style><!-- This is an automatically generated file. It will be read and overwritten. DO NOT EDIT! -->
</head>
<body>
<h2>Combo validation user guide</h2>
List of content :<br>
<ul id="list of content">
<li><a href="#introduction">Introduction</a></li>
<li><a href="#Main%20features">Main features</a></li>
<li><a href="#Usage%20%28Simple%29">Usage (Simple)</a></li>
<li><a href="links.html#Usage%20%28Simple%29">Usage
(Advanced)</a></li>
<ul>
<li><a href="#Defining%20new%20field%20type">Defining
new field type</a></li><li>Custom Validation (Under construction)</li>
</ul>
<li><a href="#Fields%20generic%20parameters%20reference">Fields
generic parameters reference</a></li>
<li><a href="#Field%20Types%20and%20parameters%20reference">Field
Types and parameters reference</a></li>
<li><a href="#Todo">Todo</a></li>
<li><a href="#Changelog">Changelog</a></li>
</ul>
<h3 id="introduction">Introduction : <a href="#list%20of%20content">[top]</a></h3>Author : Sina Salek (http://sina.salek.ws)<br>Website : http://combovalidation.sourceforge.net<br><br>This class is meant to validate HTML forms via PHP and also Javascript
&nbsp;in the simplest possible way. all you need to do is to create
an array of form fields information with require parameters and then
call few methods.<br>
<br>
<span style="font-weight: bold;">Notice :</span> As
i mentioned before, this class works pretty fine in most of the
circumstance unless you define a wrong array. unfortunately there is no
validation for the options you pass to the class so when you set a
wrong parameter, all you see is a wrong behavior. so please check the
array structure with bundled working examples and also this manual and
make sure that you
defined it correctly. and if the problem still remains then report it
as bug.<br>
<br>
<span style="font-weight: bold;">Notice : </span>this
document currently only covers basic features of this class, for
advanced features like defining new field type, customizing error
dispaly and validation functions you need to have a look at boundled
examples , inside "examples" folder.
<h3 id="Main features">Main features :&nbsp;<a href="links.html#list%20of%20content">[top]</a></h3>
<ul>
<li style="text-decoration: underline;">Customizable</li>
<ul>
<li>Validation : (defining new field types, overrding
validation functions , using regex , etc...)</li>
<li>View : ability to choose between varoius ways of showing
erros.
currently "alert,div , nearFields, pageCenterDiv, formCenterDiv
,customizedDiv" are supported out of the box. and it's also possible to
override the display function and show errors they way you want.</li>
</ul>
<li><span style="text-decoration: underline;">Cross
browser</span> (IE6+, Firefox2+, Opera7+, Safari3+, All
Mozilla based browsers)</li>
<li><span style="text-decoration: underline;">Very
well tested</span>. currently more than 30 projects are using
it</li>
<li><span style="text-decoration: underline;">Easily
integrate able</span> , All of the php&nbsp;functions
used in the class have prefix and also Accepts prefix for javascripts
for preventing conflict with other javascripts in the application</li>
<li><span style="text-decoration: underline;">Ajax
support :</span> No official Ajax support currently but since you
can
completely overwrite built in validation functions and error display
functions you can do the validation with your own Ajax framework</li>
<li><span style="text-decoration: underline;">Light
weight</span> : because it does not use any javascript
framework.</li>
<li><span style="text-decoration: underline;">Extensible</span>
: Some
design patterns like factory and chain of commands has
been used in both Javascript and PHP side for ease of extensibility.
Code is documented&nbsp;and also name of all of the methods and
functions are&nbsp;self described.</li>
<li style="text-decoration: underline;">PHP 4 &amp;
5 compatible</li>
<li style="text-decoration: underline;">Multilingual</li>
<li style="text-decoration: underline;">XHML Valid</li>
</ul>
<h3 id="Usage (Simple)">Usage (Simple) :&nbsp;<a href="links.html#list%20of%20content">[top]</a></h3>
<ul>
<li>
<h4>Step 1 : including require files<br>
</h4>
<div style="border: 1px solid orange; margin: 20px; padding: 20px;"><code><font color="#000000"><font color="#0000bb">&lt;?php
<br>
&nbsp;&nbsp;</font><font color="#007700">require_once(</font><font color="#dd0000">'lib/PEAR.php'</font><font color="#007700">);
<br>
&nbsp;&nbsp;require_once(</font><font color="#dd0000">'lib/common.inc.php'</font><font color="#007700">);
<br>
&nbsp;&nbsp;require_once(</font><font color="#dd0000">'lib/classesCore.class.inc.php'</font><font color="#007700">);
<br>
&nbsp;&nbsp;require_once(</font><font color="#dd0000">'lib/compatibility.inc.php'</font><font color="#007700">);
<br>
&nbsp;&nbsp;require_once(</font><font color="#dd0000">'validation.class.inc.php'</font><font color="#007700">);
<br>
</font><font color="#0000bb">?&gt;</font>
</font></code></div>
</li>
<li>
<h4>Step 2 : Initializing class and defining an array about
all the
form fields that need validation and set require parameters for each
one of them<br>
</h4>
<div style="border: 1px solid orange; margin: 20px; padding: 20px;"><code><font color="#000000"><font color="#0000bb">&lt;?php
<br>
$validation</font><font color="#007700">=</font><font color="#0000bb">cmfcValidation</font><font color="#007700">::</font><font color="#0000bb">factory</font><font color="#007700">(</font><font color="#dd0000">'v1'</font><font color="#007700">,array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'formName'</font><font color="#007700">=&gt;</font><font color="#dd0000">'myForm'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font></font></code><code><font color="#000000"><font color="#dd0000">'displayMethod'</font><font color="#007700">=&gt;</font><font color="#dd0000">'alert'</font><font color="#007700">,</font></font></code><code><font color="#000000"><font color="#ff8000">//possible
values : alert,div,nearFields,pageCenterDiv,formCenterDiv,customizedDiv
</font></font></code><code><font color="#000000"><font color="#ff8000"><br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'fieldsInfo'</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">"contactInfo[name]"</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'title'</font><font color="#007700">=&gt;</font><font color="#dd0000">'Name'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'type'</font><font color="#007700">=&gt;</font><font color="#dd0000">'string'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'param'</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'notEmpty'</font><font color="#007700">=&gt;</font><font color="#0000bb">true
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">"contactInfo[email]"</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'title'</font><font color="#007700">=&gt;</font><font color="#dd0000">'Email'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'type'</font><font color="#007700">=&gt;</font><font color="#dd0000">'email'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'param'</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'notEmpty'</font><font color="#007700">=&gt;</font><font color="#0000bb">true
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">"contactInfo[subject]"</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'title'</font><font color="#007700">=&gt;</font><font color="#dd0000">'Subject'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'type'</font><font color="#007700">=&gt;</font><font color="#dd0000">'string'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'param'</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'notEmpty'</font><font color="#007700">=&gt;</font><font color="#0000bb">true</font><font color="#007700">,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'lengthMin'</font><font color="#007700">=&gt;</font><font color="#0000bb">10</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'lengthMax'</font><font color="#007700">=&gt;</font><font color="#0000bb">100</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'regexp'</font><font color="#007700">=&gt;</font><font color="#dd0000">'/agreed/i'</font><font color="#007700">,</font><font color="#ff8000">//php&nbsp;regex&nbsp;with&nbsp;preg_match
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'jsRegexp'</font><font color="#007700">=&gt;</font><font color="#dd0000">'/agreed/i'</font><font color="#007700">,</font><font color="#ff8000">//javascript&nbsp;regex&nbsp;with&nbsp;preg_match
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'regexpDescription'</font><font color="#007700">=&gt;</font><font color="#dd0000">'&nbsp;:&nbsp;should&nbsp;contains&nbsp;"agreed"&nbsp;word'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">"contactInfo[description]"</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'title'</font><font color="#007700">=&gt;</font><font color="#dd0000">'Description'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'type'</font><font color="#007700">=&gt;</font><font color="#dd0000">'string'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'param'</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'notEmpty'</font><font color="#007700">=&gt;</font><font color="#0000bb">true
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">"contactInfo[tel]"</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'title'</font><font color="#007700">=&gt;</font><font color="#dd0000">'Tel'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'type'</font><font color="#007700">=&gt;</font><font color="#dd0000">'number'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'param'</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'notEmpty'</font><font color="#007700">=&gt;</font><font color="#0000bb">true</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'countMin'</font><font color="#007700">=&gt;</font><font color="#0000bb">5</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'countMax'</font><font color="#007700">=&gt;</font><font color="#0000bb">7
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">"contactInfo[age]"</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'title'</font><font color="#007700">=&gt;</font><font color="#dd0000">'Age'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'type'</font><font color="#007700">=&gt;</font><font color="#dd0000">'number'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'param'</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'notEmpty'</font><font color="#007700">=&gt;</font><font color="#0000bb">true</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'countMin'</font><font color="#007700">=&gt;</font><font color="#0000bb">2</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//min&nbsp;number&nbsp;of&nbsp;characters
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'countMax'</font><font color="#007700">=&gt;</font><font color="#0000bb">2</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//max&nbsp;number&nbsp;of&nbsp;characters
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'min'</font><font color="#007700">=&gt;</font><font color="#0000bb">18</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//min&nbsp;value
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'max'</font><font color="#007700">=&gt;</font><font color="#0000bb">60&nbsp;</font><font color="#ff8000">//max&nbsp;value
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">"contactInfo[website]"</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'title'</font><font color="#007700">=&gt;</font><font color="#dd0000">'Website'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'type'</font><font color="#007700">=&gt;</font><font color="#dd0000">'url'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'param'</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">"contactInfo[subscription]"</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'title'</font><font color="#007700">=&gt;</font><font color="#dd0000">'Subscription'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'type'</font><font color="#007700">=&gt;</font><font color="#dd0000">'checkBox'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'param'</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'notEmpty'</font><font color="#007700">=&gt;</font><font color="#0000bb">true</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;)
<br>
));
<br>
</font><font color="#0000bb">?&gt;</font>
</font></code></div>

</li>
<li>
<h4>Step 3 : customizing error messages value which is useful
if your application supports other languages (optional)<br>
</h4>
<div style="border: 1px solid orange; margin: 10px; padding: 10px;"><code><font color="#000000"><font color="#0000bb">&lt;?php
<br>
$validation</font><font color="#007700">-&gt;</font><font color="#0000bb">setOption</font><font color="#007700">(</font><font color="#dd0000">'messagesValue'</font><font color="#007700">,array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">CMF_ValidationV1_Error</font><font color="#007700">=&gt;</font><font color="#dd0000">'Unknown&nbsp;error'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">CMF_ValidationV1_Is_Not_Valid_Email</font><font color="#007700">=&gt;</font><font color="#dd0000">'"__value__"&nbsp;in&nbsp;__title__&nbsp;is&nbsp;not&nbsp;valid&nbsp;email'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">CMF_ValidationV1_Is_Not_Valid_Url</font><font color="#007700">=&gt;</font><font color="#dd0000">'"__value__"&nbsp;in&nbsp;__title__&nbsp;is&nbsp;not&nbsp;valid&nbsp;url'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">CMF_ValidationV1_Is_Not_Number</font><font color="#007700">=&gt;</font><font color="#dd0000">'"__value__"&nbsp;in&nbsp;__title__&nbsp;is&nbsp;not&nbsp;number'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">CMF_ValidationV1_Is_Not_Within_Range</font><font color="#007700">=&gt;</font><font color="#dd0000">'"__value__"&nbsp;of&nbsp;__title__&nbsp;is&nbsp;not&nbsp;within&nbsp;this&nbsp;range&nbsp;(__min__,__max__)'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">CMF_ValidationV1_Is_Not_Within_Count_Range</font><font color="#007700">=&gt;</font><font color="#dd0000">'"__value__"&nbsp;of&nbsp;__title__&nbsp;is&nbsp;not&nbsp;within&nbsp;this&nbsp;count&nbsp;range&nbsp;(__min__,__max__)'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">CMF_ValidationV1_Is_Empty</font><font color="#007700">=&gt;</font><font color="#dd0000">'__title__&nbsp;value&nbsp;should&nbsp;not&nbsp;be&nbsp;empty'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">CMF_ValidationV1_Is_Not_Selected</font><font color="#007700">=&gt;</font><font color="#dd0000">'__title__&nbsp;is&nbsp;not&nbsp;selected'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">CMF_ValidationV1_Is_Not_Within_Length_Range</font><font color="#007700">=&gt;</font><font color="#dd0000">'"__value__"&nbsp;of&nbsp;__title__&nbsp;is&nbsp;not&nbsp;within&nbsp;this&nbsp;length&nbsp;range&nbsp;(__min__,__max__)'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">CMF_ValidationV1_Is_Not_String</font><font color="#007700">=&gt;</font><font color="#dd0000">'__title__&nbsp;is&nbsp;not&nbsp;string'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">CMF_ValidationV1_Is_Not_Match_With_Pattern</font><font color="#007700">=&gt;</font><font color="#dd0000">'__title__&nbsp;is&nbsp;not&nbsp;match&nbsp;with&nbsp;__desc__'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">CMF_ValidationV1_Field_Does_No_Exists</font><font color="#007700">=&gt;</font><font color="#dd0000">'__title__&nbsp;field&nbsp;"__fieldName__"&nbsp;does&nbsp;not&nbsp;exists'
<br>
</font><font color="#007700">));
<br>
</font><font color="#0000bb">?&gt;</font>
</font></code></div>

</li>
<li><span style="font-weight: bold;">Step 4 :
calling require methods for javascript validation inside page body ta<span style="font-family: monospace;">g</span></span><br>
<div style="border: 1px solid orange; margin: 10px; padding: 10px;"><code><font color="#000000">&lt;body&gt;
<br>
<font color="#0000bb">&lt;?php
<br>
&nbsp;&nbsp;$validation</font><font color="#007700">-&gt;</font><font color="#0000bb">printJsClass</font><font color="#007700">();
<br>
&nbsp;&nbsp;</font><font color="#0000bb">$validation</font><font color="#007700">-&gt;</font><font color="#0000bb">printJsInstance</font><font color="#007700">();
<br>
</font><font color="#0000bb">?&gt;
<br>
</font>&lt;form&gt;&nbsp;...</font>
</code></div>
</li>
<li><span style="font-weight: bold;">Step 5 :
validating submitted form via PHP<br>
<br>
</span>
<div style="border: 1px solid orange; margin: 10px; padding: 10px;"><code><font color="#000000"><font color="#0000bb">&lt;?php
<br>
</font><font color="#007700">&nbsp;&nbsp;</font><font color="#ff8000">/**
<br>
&nbsp;&nbsp;&nbsp;*&nbsp;validating&nbsp;form&nbsp;via&nbsp;package
<br>
&nbsp;&nbsp;&nbsp;*/
<br>
&nbsp;&nbsp;</font><font color="#0000bb">$validateResult&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000bb">$validation</font><font color="#007700">-&gt;</font><font color="#0000bb">validate</font><font color="#007700">(</font></font></code><code><font color="#000000"><font color="#0000bb">$_POST</font></font></code><code><font color="#000000"><font color="#007700">);
<br>
&nbsp;&nbsp;
<br>
&nbsp;&nbsp;if&nbsp;(empty(</font><font color="#0000bb">$validateResult</font><font color="#007700">))&nbsp;{
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">$messages</font><font color="#007700">[]&nbsp;=&nbsp;</font><font color="#dd0000">'Bingo!'</font><font color="#007700">;
<br>
&nbsp;&nbsp;}&nbsp;else&nbsp;{
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(</font><font color="#0000bb">$validateResult&nbsp;</font><font color="#007700">as&nbsp;</font><font color="#0000bb">$r</font><font color="#007700">)&nbsp;{
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">$messages</font><font color="#007700">[]&nbsp;=&nbsp;</font><font color="#0000bb">$r</font><font color="#007700">-&gt;</font><font color="#0000bb">getMessage</font><font color="#007700">();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">$successfulSubmit&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000bb">0</font><font color="#007700">;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
&nbsp;&nbsp;}
<br>
</font><font color="#0000bb">?&gt;
<br>
</font></font></code><code></code></div>
</li>
</ul>
<h3 id="Usage (Simple)">Usage (Advanced) :&nbsp;<a href="links.html#list%20of%20content">[top]</a></h3>
<ul>
<li>
<h4 id="Defining new field type">Defining new field
type<br></h4><div style="border: 1px solid orange; margin: 20px; padding: 20px;"><code><font color="#000000"><font color="#0000bb">&lt;?php
</font></font></code><code><font color="#000000"><font color="#007700">&nbsp;<br>
</font><font style="color: black;" color="#dd0000">$validation=cmfcValidation::factory('v1',array(<br>&nbsp;&nbsp;&nbsp; 'formName'=&gt;'myForm',<br>&nbsp;&nbsp;&nbsp; 'fieldTypesInfo'=&gt;array(<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;'age'=&gt;array(<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'validationHandler'=&gt;array(<br>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;'function'=&gt;'validateAge' //name of the function or array of
the object method array(&amp;obj,'methodName')<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;),<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'jsValidationHandler'=&gt;array(<br>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;'function'=&gt;'validateAge' //name of the function or array of
the object method array(&amp;obj,'methodName')<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;)<br>&nbsp;&nbsp;&nbsp; ),</font><font color="#007700"> <br>&nbsp;&nbsp;&nbsp; ...<br>
</font><font color="#0000bb">?&gt;</font>
</font></code></div>Require PHP function :<div style="border: 1px solid orange; margin: 20px; padding: 20px;"><code><font color="#000000"><font color="#0000bb">&lt;?php
</font></font></code><code><font color="#000000"><font color="#007700">&nbsp;<br>
</font><font style="color: black;" color="#dd0000">function validateAge($validation,$fieldsValues,$fieldInfo,$patternName) {<br>&nbsp;&nbsp;&nbsp; $fieldValue=$fieldsValues[$fieldInfo['headName']];<br>&nbsp;&nbsp;&nbsp; $isValid=false;<br>&nbsp;&nbsp;&nbsp; if (is_numeric($fieldValue))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if ($fieldValue&gt;=1 and $fieldValue&lt;=100)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;$isValid=true;<br>&nbsp;&nbsp;&nbsp; if (!$isValid)<br>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;return $validation-&gt;raiseError('Age should be number and between
1-100' ,'', PEAR_ERROR_RETURN, NULL,
array('title'=&gt;$fieldInfo['title'],'value'=&gt;$fieldValue));<br>}</font><font color="#007700"><span style="color: black;">&nbsp;</span></font><font color="#007700">&nbsp;<br>
</font><font color="#0000bb">?&gt;</font>
</font></code></div>Require Javascript function :&nbsp;<div style="border: 1px solid orange; margin: 20px; padding: 20px;"><code><font color="#000000"><font color="#0000bb">&lt;script&gt;&nbsp;</font></font></code><code><font color="#000000"><font color="#007700">&nbsp;<br>
</font><font style="color: black;" color="#dd0000">/**<br>* function for validating new field type<br>&nbsp;*/<br>function validateAge(validation,fieldInfo,fieldValue) {<br>&nbsp;&nbsp;&nbsp; if (fieldValue&gt;=1 &amp;&amp; fieldValue&lt;=100)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; return '';<br>&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; return validation.raiseError('__title__ should be number and between
1-100','','ERROR_RETURN',null, {'title':fieldInfo['title']} );<br>}</font><font color="#007700"><span style="color: black;"> </span></font><font color="#007700">&nbsp;<br></font>&lt;/script&gt;
</font></code></div><h4 id="Defining new field type"><span style="font-weight: normal;">You can now use "age" as field type for any of fields you want :)</span> </h4>
</li>
</ul>
<h3 id="Fields generic parameters reference">Fields
generic parameters reference :<a href="links.html#list%20of%20content"> [top]</a></h3>
<ul>
<li>title //string , title of the field that will be use in
error messages</li>
<li>type //string , field type name. can be name of a custom
field type</li>
<li>likeType //string, base field type name. when you have a
custom field type you can choose its base type. for example when type
is "age" base type can be number</li>
<li>jsMessageBoardId //string, id of the field message holder
html element (can be a DIV), useful if display method is nearfields</li>
<li>type //string, field type name</li>
<li>param //array, field type specific parameters</li>
</ul>
<div style="border: 1px solid orange; margin: 20px; padding: 20px;"><code><font color="#000000"><font color="#0000bb">&lt;?php
</font></font></code><code><font color="#000000"><font color="#007700">&nbsp;<br>
</font><font color="#dd0000">"contactInfo[subject]"</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'title'</font><font color="#007700">=&gt;</font><font color="#dd0000">'Subject'</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'type'</font><font color="#007700">=&gt;</font><font color="#dd0000">'string'</font><font color="#007700">,
<br>
<span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span></font><font style="color: black;" color="#dd0000">'param'</font><font style="color: black;" color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font style="color: black;" color="#dd0000">'notEmpty'</font><font style="color: black;" color="#007700">=&gt;</font><font style="color: black;" color="#0000bb">true</font><font style="color: black;" color="#007700">,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font style="color: black;" color="#dd0000">'lengthMin'</font><font style="color: black;" color="#007700">=&gt;</font><font style="color: black;" color="#0000bb">10</font><font style="color: black;" color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
....</font><font color="#007700"><br style="color: black;">
<span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)
</span><br>
),
</font><font color="#007700">&nbsp;<br>
</font><font color="#0000bb">?&gt;</font>
</font></code></div>
<h3 id="Field Types and parameters reference">Field Types
and parameters reference :&nbsp;<a href="links.html#list%20of%20content">[top]</a></h3>
<div style="border: 1px solid orange; margin: 20px; padding: 20px;"><code><font color="#000000"><font color="#0000bb">&lt;?php
</font></font></code><code><font color="#000000"><font color="#007700">&nbsp;<br>
</font><font style="color: black;" color="#dd0000">"contactInfo[subject]"</font><font style="color: black;" color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font style="color: black;" color="#dd0000">'title'</font><font style="color: black;" color="#007700">=&gt;</font><font style="color: black;" color="#dd0000">'Subject'</font><font style="color: black;" color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font style="color: black;" color="#dd0000">'type'</font><font style="color: black;" color="#007700">=&gt;</font><font style="color: black;" color="#dd0000">'string'</font><font color="#007700"><span style="color: black;">,
</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'param'</font><font color="#007700">=&gt;array(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'notEmpty'</font><font color="#007700">=&gt;</font><font color="#0000bb">true</font><font color="#007700">,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#dd0000">'lengthMin'</font><font color="#007700">=&gt;</font><font color="#0000bb">10</font><font color="#007700">,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
....</font><font color="#007700"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)
<br>
<span style="color: black;">),
</span></font><font color="#007700">&nbsp;<br>
</font><font color="#0000bb">?&gt;</font>
</font></code></div>
<ul>
<li>string</li>
<ul>
<li>notEmpty //boolean : prevent field value from
being&nbsp;empty</li>
</ul>
<ul>
<li>lengthMin //integer : minimum acceptable number of string
characters</li>
<li>lengthMax //integer : maximum acceptable number of string
characters</li>
<li>regexp //string : PHP preg_match compatible regular
expression. sample (/agreed/i)</li>
<li>jsRegexp //string : Javascript compatible regular
expression. sample (/agreed/i)</li>
<li>regexpDescription
//string : message describing conditions defined in regex for showing
to user ,sample (should contains "agreed" word')</li>
</ul>
<li>email</li>
<ul>
<li>notEmpty //boolean : prevent field value from
being&nbsp;empty</li>
</ul>
<li>number</li>
<ul>
<li>notEmpty //boolean : prevent field value from
being&nbsp;empty<code></code></li>
<li>countMin&nbsp;//integer : minimum acceptable number
of numbers , similar to&nbsp;lengthMin but only for numbers</li>
<li>countMax //integer : maximum acceptable number of numbers
, similar to&nbsp;lengthMax but only for numbers</li>
<li>min&nbsp; //integer : smallest acceptable number <span style="font-family: monospace;"></span></li>
<li>max //integer :&nbsp;biggest acceptable number</li>
</ul>
<li>url</li>
<ul>
<li>notEmpty //boolean : prevent field value from
being&nbsp;empty</li>
</ul>
<li>checkbox<span style="font-family: monospace;">
</span>(for checking HTML input checkboxes)</li>
<ul>
<li>notEmpty //boolean : prevent field value from
being&nbsp;empty</li>
</ul>
<li>dropDownDate //currently only this strucutre can be
validated : fieldName[year] , fieldName[month],&nbsp;fieldName[day]
</li>
<ul>
<li>notEmpty //boolean : prevent field value from
being&nbsp;empty</li>
</ul>
<li>password</li>
<ul>
<li>notEmpty //boolean : prevent field value from
being&nbsp;empty</li>
<li>confirmationFieldName //string : name of the password
confirmation field</li>
</ul>
<li>array</li>
<ul>
<li>notEmpty //boolean : prevent field value from
being&nbsp;empty</li>
</ul>
</ul>
<h3 id="Todo">Todo :&nbsp;<a href="links.html#list%20of%20content">[top]</a></h3>
<ul>
<li>Better error reporting for class methods and options</li>
<li>Validation for fields info and parameters</li>
<li>Making it jquery compatible (optional)</li>
<li>Validation should work with multiply forms in one page (by
adding formName item to each fieldInfo)</li>
<li>Single javascript class in web page with multiply
instance,validation instances should be connected</li>
<li>Special methods for ease of validation via Ajax</li>
<li>Support three type of messages , warning , information ,
error</li>
<li>Compress javascripts</li>
</ul>
<h3 id="Changelog">Changelog :&nbsp;<a href="links.html#list%20of%20content">[top]</a></h3>
<ul>
<li>in firefox when form defines in non w3c way, firefox cann't
find the fields inside it. it should throw an error</li>
<li>getElementsByName() issue with multiRadioBoxes and
multiCheckBoxes solved&nbsp;</li>
<li>supporting for new type "array"</li>
<li>optimizing getFormFieldObject() for large forms</li>
<li>if formName does not define, it will for the fields in the
whole document</li>
<li>support finding the field value via only field name without
pattern name</li>
<li>tested with PHP 4.x and PHP 5.2.x</li>
<li>completely tested with IE 6.x,7.x , Firefox 2.x , Opera 9.x
, Safari 3.x</li>
<li>ajax support via comppletely overriding object display or
validation function</li>
<li>custom field type</li>
<li>customizing error messages</li>
<li>override display function</li>
<li>custom new display modes</li>
<li>overriding or extending validation functions
(validate,validateAfter,validateBefore)</li>
<li>limited custom validation for fields which have need
regular validations like notEmpty and also some more</li>
<li>chain of commands pattern support for javascript and php</li>
<li>validate fields with regular expression (javascript
&amp; php)<br>
</li>
</ul>
Hope you enjoy it,&nbsp;any kind of contributions are
welcome :)<br>
<span style="font-style: italic;">This document has been
created with <a href="http://kompozer.sourceforge.net/">Kompozer</a>
</span>&nbsp;(Great open source HTML editor)<span style="text-decoration: underline;"></span>
</body></html>
Return current item: Combo Validation