summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2006-01-16 05:26:31 +0000
committerxue <>2006-01-16 05:26:31 +0000
commitacfdc83a0bb620d996c80a0787fd515121fcdca0 (patch)
tree048cdd4248f0110d37006a4c9c2c2306a122aa76
parent6da2f379b1b4ddd0c27db2185ca7408b43a9a97a (diff)
Added validator controls.
-rw-r--r--.gitattributes8
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.page54
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.php8
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.page57
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.php8
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.page2
-rw-r--r--demos/quickstart/protected/pages/Controls/Validation.page25
-rw-r--r--framework/Web/UI/WebControls/TCompareValidator.php266
-rw-r--r--framework/Web/UI/WebControls/TCustomValidator.php161
-rw-r--r--framework/Web/UI/WebControls/TRegularExpressionValidator.php97
-rw-r--r--framework/Web/UI/WebControls/TRequiredFieldValidator.php33
-rw-r--r--framework/Web/UI/WebControls/TValidationSummary.php405
-rw-r--r--framework/core.php3
13 files changed, 1124 insertions, 3 deletions
diff --git a/.gitattributes b/.gitattributes
index 7b83e1a2..72f7ddb1 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -48,6 +48,8 @@ demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample1.page -text
demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample1.php -text
demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php -text
+demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.page -text
+demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TLabel/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.php -text
@@ -56,6 +58,8 @@ demos/quickstart/protected/pages/Controls/Samples/TPanel/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TPanel/hello_world.gif -text
demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php -text
+demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.page -text
+demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TTable/Home.page -text
@@ -520,8 +524,10 @@ framework/Web/UI/WebControls/TButton.php -text
framework/Web/UI/WebControls/TButtonColumn.php -text
framework/Web/UI/WebControls/TCheckBox.php -text
framework/Web/UI/WebControls/TCheckBoxList.php -text
+framework/Web/UI/WebControls/TCompareValidator.php -text
framework/Web/UI/WebControls/TContent.php -text
framework/Web/UI/WebControls/TContentPlaceHolder.php -text
+framework/Web/UI/WebControls/TCustomValidator.php -text
framework/Web/UI/WebControls/TDataBoundControl.php -text
framework/Web/UI/WebControls/TDataGrid.php -text
framework/Web/UI/WebControls/TDataGridColumn.php -text
@@ -549,6 +555,7 @@ framework/Web/UI/WebControls/TPanel.php -text
framework/Web/UI/WebControls/TPlaceHolder.php -text
framework/Web/UI/WebControls/TRadioButton.php -text
framework/Web/UI/WebControls/TRadioButtonList.php -text
+framework/Web/UI/WebControls/TRegularExpressionValidator.php -text
framework/Web/UI/WebControls/TRepeatInfo.php -text
framework/Web/UI/WebControls/TRepeater.php -text
framework/Web/UI/WebControls/TRequiredFieldValidator.php -text
@@ -558,6 +565,7 @@ framework/Web/UI/WebControls/TTable.php -text
framework/Web/UI/WebControls/TTemplateColumn.php -text
framework/Web/UI/WebControls/TTextBox.php -text
framework/Web/UI/WebControls/TTextHighlighter.php -text
+framework/Web/UI/WebControls/TValidationSummary.php -text
framework/Web/UI/WebControls/TWebControl.php -text
framework/core.php -text
framework/prado.php -text
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.page
new file mode 100644
index 00000000..bbeef3fd
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.page
@@ -0,0 +1,54 @@
+<com:TContent ID="body">
+
+<h1>TEmailAddressValidator Samples</h1>
+
+<table class="sampletable">
+
+<tr>
+<td class="samplenote">
+Email address validator with default settings:
+</td>
+<td class="sampleaction">
+<com:TTextBox ID="TextBox1" />
+<com:TEmailAddressValidator
+ ValidationGroup="Group1"
+ ControlToValidate="TextBox1"
+ Text="Invalid email address." />
+<com:TButton Text="Submit" ValidationGroup="Group1" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Email address validator with client-side validation disabled:
+</td>
+<td class="sampleaction">
+<com:TTextBox ID="TextBox2" />
+<com:TEmailAddressValidator
+ ValidationGroup="Group2"
+ EnableClientScript="false"
+ ControlToValidate="TextBox2"
+ Text="Invalid email address." />
+<com:TButton Text="Submit" ValidationGroup="Group2" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Email address validator with focus-on-error enabled and dynamic display:
+</td>
+<td class="sampleaction">
+<com:TTextBox ID="TextBox3" />
+<com:TEmailAddressValidator
+ ValidationGroup="Group3"
+ ControlToValidate="TextBox3"
+ Display="Dynamic"
+ Text="Invalid email address." />
+<com:TButton Text="Submit" ValidationGroup="Group3" />
+</td>
+</tr>
+
+
+</table>
+
+</com:TContent> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.php
new file mode 100644
index 00000000..88d2dbf2
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.php
@@ -0,0 +1,8 @@
+<?php
+
+class Home extends TPage
+{
+
+}
+
+?> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.page
new file mode 100644
index 00000000..ac93715d
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.page
@@ -0,0 +1,57 @@
+<com:TContent ID="body">
+
+<h1>TRegularExpressionValidator Samples</h1>
+
+<table class="sampletable">
+
+<tr>
+<td class="samplenote">
+Regular expression validator with default settings:
+</td>
+<td class="sampleaction">
+<com:TTextBox ID="TextBox1" />
+<com:TRegularExpressionValidator
+ ValidationGroup="Group1"
+ ControlToValidate="TextBox1"
+ RegularExpression="\w+"
+ Text="Only word characters are allowed." />
+<com:TButton Text="Submit" ValidationGroup="Group1" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Regular expression validator with client-side validation disabled:
+</td>
+<td class="sampleaction">
+<com:TTextBox ID="TextBox2" />
+<com:TRegularExpressionValidator
+ ValidationGroup="Group2"
+ EnableClientScript="false"
+ ControlToValidate="TextBox2"
+ RegularExpression="\w+"
+ Text="Only word characters are allowed." />
+<com:TButton Text="Submit" ValidationGroup="Group2" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Regular expression validator with focus-on-error enabled and dynamic display:
+</td>
+<td class="sampleaction">
+<com:TTextBox ID="TextBox3" />
+<com:TRegularExpressionValidator
+ ValidationGroup="Group3"
+ ControlToValidate="TextBox3"
+ Display="Dynamic"
+ RegularExpression="\w+"
+ Text="Only word characters are allowed." />
+<com:TButton Text="Submit" ValidationGroup="Group3" />
+</td>
+</tr>
+
+
+</table>
+
+</com:TContent> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.php
new file mode 100644
index 00000000..88d2dbf2
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.php
@@ -0,0 +1,8 @@
+<?php
+
+class Home extends TPage
+{
+
+}
+
+?> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.page
index 8b061691..36d02ced 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.page
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.page
@@ -35,7 +35,7 @@ Required field validator with client-side validation disabled:
<tr>
<td class="samplenote">
-Required field validator with default settings:
+Required field validator with focus-on-error enabled and dynamic display:
</td>
<td class="sampleaction">
<com:TTextBox ID="TextBox3" />
diff --git a/demos/quickstart/protected/pages/Controls/Validation.page b/demos/quickstart/protected/pages/Controls/Validation.page
index 7e8a5a8d..b0bf46e1 100644
--- a/demos/quickstart/protected/pages/Controls/Validation.page
+++ b/demos/quickstart/protected/pages/Controls/Validation.page
@@ -7,4 +7,29 @@
</p>
<com:RunBar PagePath="Controls.Samples.TRequiredFieldValidator.Home" />
+<h2>TRegularExpressionValidator</h2>
+<p>
+</p>
+<com:RunBar PagePath="Controls.Samples.TRegularExpressionValidator.Home" />
+
+<h2>TEmailAddressValidator</h2>
+<p>
+</p>
+<com:RunBar PagePath="Controls.Samples.TEmailAddressValidator.Home" />
+
+<h2>TEmailAddressValidator</h2>
+<p>
+</p>
+<com:RunBar PagePath="Controls.Samples.TEmailAddressValidator.Home" />
+
+<h2>TCompareValidator</h2>
+<p>
+</p>
+<com:RunBar PagePath="Controls.Samples.TCompareValidator.Home" />
+
+<h2>TCustomValidator</h2>
+<p>
+</p>
+<com:RunBar PagePath="Controls.Samples.TCustomValidator.Home" />
+
</com:TContent> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TCompareValidator.php b/framework/Web/UI/WebControls/TCompareValidator.php
new file mode 100644
index 00000000..b7363792
--- /dev/null
+++ b/framework/Web/UI/WebControls/TCompareValidator.php
@@ -0,0 +1,266 @@
+<?php
+/**
+ * TCompareValidator class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TBaseValidator class
+ */
+Prado::using('System.Web.UI.WebControls.TBaseValidator');
+
+/**
+ * TCompareValidator class
+ *
+ * TCompareValidator compares the value entered by the user into an input component with the value
+ * entered into another input component or a constant value. To specify the input component to
+ * validate, set the <b>ControlToValidate</b> property to the ID of the input component.
+ *
+ * To compare the associated input component with another input component,
+ * set the <b>ControlToCompare</b> property to the ID of the component to compare with.
+ *
+ * To compare the associated input component with a constant value,
+ * specify the constant value to compare with by setting the <b>ValueToCompare</b> property.
+ *
+ * The <b>ValueType</b> property is used to specify the data type of both comparison values.
+ * Both values are automatically converted to this data type before the comparison operation
+ * is performed. The following value types are supported:
+ * - <b>Integer</b> A 32-bit signed integer data type.
+ * - <b>Double</b> A double-precision floating point number data type.
+ * - <b>Currency</b> A decimal data type that can contain currency symbols.
+ * - <b>Date</b> A date data type. The format follows the GNU date syntax.
+ * - <b>String</b> A string data type.
+ *
+ * Use the <b>Operator</b> property to specify the type of comparison to perform,
+ * such as Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual, DataTypeCheck.
+ * If you set the <b>Operator</b> property to DataTypeCheck, the TCompareValidator component
+ * will ignore the <b>ControlToCompare</b> and <b>ValueToCompare</b> properties and simply
+ * indicates whether the value entered into the input component can be converted to the data type
+ * specified by the <b>ValueType</b> property.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TCompareValidator extends TBaseValidator
+{
+ /**
+ * @return string the data type that the values being compared are converted to before the comparison is made. Defaults to String.
+ */
+ public function getValueType()
+ {
+ return $this->getViewState('ValueType','String');
+ }
+
+ /**
+ * Sets the data type (Integer, Double, Currency, Date, String) that the values being compared are converted to before the comparison is made.
+ * @param string the data type
+ */
+ public function setValueType($value)
+ {
+ $this->setViewState('ValueType',TPropertyValue::ensureEnum($value,'Integer','Double','Date','Currency','String'),'String');
+ }
+
+ /**
+ * @return string the input component to compare with the input control being validated.
+ */
+ public function getControlToCompare()
+ {
+ return $this->getViewState('ControlToCompare','');
+ }
+
+ /**
+ * Sets the input component to compare with the input control being validated.
+ * @param string the ID path of the component to compare with
+ */
+ public function setControlToCompare($value)
+ {
+ $this->setViewState('ControlToCompare',$value,'');
+ }
+
+ /**
+ * @return string the constant value to compare with the value entered by the user into the input component being validated.
+ */
+ public function getValueToCompare()
+ {
+ return $this->getViewState('ValueToCompare','');
+ }
+
+ /**
+ * Sets the constant value to compare with the value entered by the user into the input component being validated.
+ * @param string the constant value
+ */
+ public function setValueToCompare($value)
+ {
+ $this->setViewState('ValueToCompare',$value,'');
+ }
+
+ /**
+ * @return string the comparison operation to perform (Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual, DataTypeCheck). Defaults to Equal.
+ */
+ public function getOperator()
+ {
+ return $this->getViewState('Operator','Equal');
+ }
+
+ /**
+ * Sets the comparison operation to perform (Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual, DataTypeCheck)
+ * @param string the comparison operation
+ */
+ public function setOperator($value)
+ {
+ $this->setViewState('Operator',TPropertyValue::ensureEnum($value,'Equal','NotEqual','GreaterThan','GreaterThanEqual','LessThan','LessThanEqual','DataTypeCheck'),'Equal');
+ }
+
+ /**
+ * Sets the date format for a date validation
+ * @param string the date format value
+ */
+ public function setDateFormat($value)
+ {
+ $this->setViewState('DateFormat', $value, '');
+ }
+
+ /**
+ * @return string the date validation date format if any
+ */
+ public function getDateFormat()
+ {
+ return $this->getViewState('DateFormat', '');
+ }
+
+ /**
+ * This method overrides the parent's implementation.
+ * The validation succeeds if the input data compares successfully.
+ * The validation always succeeds if ControlToValidate is not specified
+ * or the input data is empty.
+ * @return boolean whether the validation succeeds
+ */
+ public function evaluateIsValid()
+ {
+ if(($control=$this->getValidationTarget())===null)
+ throw new TInvalidDataValueException('comparevalidator_controltovalidate_invalid');
+ if(($value=$this->getValidationValue($control))==='')
+ return true;
+
+ if($this->getOperator()==='DataTypeCheck')
+ return $this->evaluateDataTypeCheck($value);
+
+ if(($controlToCompare=$this->getControlToCompare())!=='')
+ {
+ if(($control2=$this->findControl($controlToCompare))===null)
+ throw new TInvalidDataValueException('comparevalidator_controltocompare_invalid');
+ if(($value2=$this->getValidationValue($control2))==='')
+ return false;
+ }
+ else
+ $value2=$this->getValueToCompare();
+
+ $values = $this->getComparisonValues($value, $value2);
+ switch($this->getOperator())
+ {
+ case 'Equal':
+ return $values[0] == $values[1];
+ case 'NotEqual':
+ return $values[0] != $values[1];
+ case 'GreaterThan':
+ return $values[0] > $values[1];
+ case 'GreaterThanEqual':
+ return $values[0] >= $values[1];
+ case 'LessThan':
+ return $values[0] < $values[1];
+ case 'LessThanEqual':
+ return $values[0] <= $values[1];
+ }
+
+ return false;
+ }
+
+ /**
+ * Determine if the given value is of a particular type using RegExp.
+ * @param string value to check
+ * @return boolean true if value fits the type expression.
+ */
+ protected function evaluateDataTypeCheck($value)
+ {
+ switch($this->getValueType())
+ {
+ case 'Integer':
+ return preg_match('/^[-+]?[0-9]+$/',trim($value));
+ case 'Float':
+ case 'Double':
+ return preg_match('/^[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?$/',trim($value));
+ case 'Currency':
+ return preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?$/',trim($value));
+ case 'Date':
+ $dateFormat = $this->getDateFormat();
+ if(strlen($dateFormat))
+ return pradoParseDate($value, $dateFormat) !== null;
+ else
+ return strtotime($value) > 0;
+ }
+ return true;
+ }
+
+ /**
+ * Parse the pair of values into the appropriate value type.
+ * @param string value one
+ * @param string second value
+ * @return array appropriate type of the value pair, array($value1, $value2);
+ */
+ protected function getComparisonValues($value1, $value2)
+ {
+ switch($this->getValueType())
+ {
+ case 'Integer':
+ return array(intval($value1), intval($value2));
+ case 'Float':
+ case 'Double':
+ return array(floatval($value1), floatval($value2));
+ case 'Currency':
+ if(preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?/',$value1,$matches))
+ $value1=floatval($matches[0]);
+ else
+ $value1=0;
+ if(preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?/',$value2,$matches))
+ $value2=floatval($matches[0]);
+ else
+ $value2=0;
+ return array($value1, $value2);
+ case 'Date':
+ $dateFormat = $this->getDateFormat();
+ if (strlen($dateFormat))
+ return array(pradoParseDate($value1, $dateFormat), pradoParseDate($value2, $dateFormat));
+ else
+ return array(strtotime($value1), strtotime($value2));
+ }
+ return array($value1, $value2);
+ }
+
+ protected function getClientScriptOptions()
+ {
+ $options = parent::getClientScriptOptions();
+ if(($name=$this->getControlToCompare())!=='')
+ {
+ if(($control=$this->findControl($name))!==null)
+ $options['controltocompare']=$options['controlhookup']=$control->getClientID();
+ }
+ if(($value=$this->getValueToCompare())!=='')
+ $options['valuetocompare']=$value;
+ if(($operator=$this->getOperator())!=='Equal')
+ $options['operator']=$operator;
+ $options['type']=$this->getValueType();
+ if(($dateFormat=$this->getDateFormat())!=='')
+ $options['dateformat']=$dateFormat;
+ return $options;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TCustomValidator.php b/framework/Web/UI/WebControls/TCustomValidator.php
new file mode 100644
index 00000000..bf80e644
--- /dev/null
+++ b/framework/Web/UI/WebControls/TCustomValidator.php
@@ -0,0 +1,161 @@
+<?php
+/**
+ * TCustomValidator class file
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: 1.7 $ $Date: 2005/06/13 07:04:28 $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TValidator class file
+ */
+require_once(dirname(__FILE__).'/TValidator.php');
+
+/**
+ * TCustomValidator class
+ *
+ * TCustomValidator performs user-defined validation (either
+ * server-side or client-side or both) on an input component.
+ *
+ * To create a server-side validation function, provide a handler for
+ * the <b>OnServerValidate</b> event that performs the validation.
+ * The data string of the input component to validate can be accessed
+ * by the <b>value</b> property of the event parameter which is of type
+ * <b>TServerValidateEventParameter</b>. The result of the validation
+ * should be stored in the <b>isValid</b> property of the event parameter.
+ *
+ * To create a client-side validation function, add the client-side
+ * validation javascript function to the page template.
+ * The function should have the following signature:
+ * <code>
+ * <script type="text/javascript"><!--
+ * function ValidationFunctionName(sender, parameter)
+ * {
+ * // if(parameter == ...)
+ * // return true;
+ * // else
+ * // return false;
+ * }
+ * --></script>
+ * </code>
+ * Use the <b>ClientValidationFunction</b> property to specify the name of
+ * the client-side validation script function associated with the TCustomValidator.
+ *
+ * Namespace: System.Web.UI.WebControls
+ *
+ * Properties
+ * - <b>ClientValidationFunction</b>, string, kept in viewstate
+ * <br>Gets or sets the name of the custom client-side script function used for validation.
+ *
+ * Events
+ * - <b>OnServerValidate</b> Occurs when validation is performed on the server.
+ * <br>Event delegates must set the event parameter TServerValidateEventParameter.isValid
+ * to false if they find the value is invalid.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version v1.0, last update on 2004/08/13 21:44:52
+ * @package System.Web.UI.WebControls
+ */
+class TCustomValidator extends TValidator
+{
+ /**
+ * @return string the name of the custom client-side script function used for validation.
+ */
+ public function getClientValidationFunction()
+ {
+ return $this->getViewState('ClientValidationFunction','');
+ }
+
+ /**
+ * Sets the name of the custom client-side script function used for validation.
+ * @param string the script function name
+ */
+ public function setClientValidationFunction($value)
+ {
+ $this->setViewState('ClientValidationFunction',$value,'');
+ }
+
+ /**
+ * This method overrides the parent's implementation.
+ * The validation succeeds if {@link onServerValidate} returns true.
+ * @return boolean whether the validation succeeds
+ */
+ public function evaluateIsValid()
+ {
+ $idPath=$this->getControlToValidate();
+ if(strlen($idPath))
+ {
+ $control=$this->getTargetControl($idPath);
+ $value=$control->getValidationPropertyValue($idPath);
+ return $this->onServerValidate($value);
+ }
+ else
+ return true;
+ }
+
+ /**
+ * This method is invoked when the server side validation happens.
+ * It will raise the <b>OnServerValidate</b> event.
+ * The method also allows derived classes to handle the event without attaching a delegate.
+ * <b>Note</b> The derived classes should call parent implementation
+ * to ensure the <b>OnServerValidate</b> event is raised.
+ * @param string the value to be validated
+ * @return boolean whether the value is valid
+ */
+ public function onServerValidate($value)
+ {
+ $param=new TServerValidateEventParameter;
+ $param->value=$value;
+ $param->isValid=true;
+ $this->raiseEvent('OnServerValidate',$this,$param);
+ return $param->isValid;
+ }
+
+ /**
+ * Get a list of options for the client-side javascript validator
+ * @return array list of options for the validator
+ */
+ protected function getJsOptions()
+ {
+ $options = parent::getJsOptions();
+ $clientJs = $this->getClientValidationFunction();
+ if(strlen($clientJs))
+ $options['clientvalidationfunction']=$clientJs;
+ return $options;
+ }
+}
+
+/**
+ * TServerValidateEventParameter class
+ *
+ * TServerValidateEventParameter encapsulates the parameter data for
+ * <b>OnServerValidate</b> event of TCustomValidator components.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version v1.0, last update on 2004/08/13 21:44:52
+ * @package System.Web.UI.WebControls
+ */
+class TServerValidateEventParameter extends TEventParameter
+{
+ /**
+ * the value to be validated
+ * @var string
+ */
+ public $value='';
+ /**
+ * whether the value is valid
+ * @var boolean
+ */
+ public $isValid=true;
+}
+?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TRegularExpressionValidator.php b/framework/Web/UI/WebControls/TRegularExpressionValidator.php
new file mode 100644
index 00000000..9fe0f778
--- /dev/null
+++ b/framework/Web/UI/WebControls/TRegularExpressionValidator.php
@@ -0,0 +1,97 @@
+<?php
+/**
+ * TRequiredFieldValidator class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TBaseValidator class
+ */
+Prado::using('System.Web.UI.WebControls.TBaseValidator');
+
+/**
+ * TRegularExpressionValidator class
+ *
+ * TRegularExpressionValidator validates whether the value of an associated
+ * input component matches the pattern specified by a regular expression.
+ *
+ * You can specify the regular expression by setting the <b>RegularExpression</b>
+ * property. Some commonly used regular expressions include:
+ * <pre>
+ * French Phone Number: (0( \d|\d ))?\d\d \d\d(\d \d| \d\d )\d\d
+ * French Postal Code: \d{5}
+ * German Phone Number: ((\(0\d\d\) |(\(0\d{3}\) )?\d )?\d\d \d\d \d\d|\(0\d{4}\) \d \d\d-\d\d?)
+ * German Postal Code: (D-)?\d{5}
+ * Email Address: \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
+ * Internal URL: http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
+ * Japanese Phone Number: (0\d{1,4}-|\(0\d{1,4}\) ?)?\d{1,4}-\d{4}
+ * Japanese Postal Code: \d{3}(-(\d{4}|\d{2}))?
+ * P.R.C. Phone Number: (\(\d{3}\)|\d{3}-)?\d{8}
+ * P.R.C. Postal Code: \d{6}
+ * P.R.C. Social Security Number: \d{18}|\d{15}
+ * U.S. Phone Number: ((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}
+ * U.S. ZIP Code: \d{5}(-\d{4})?
+ * U.S. Social Security Number: \d{3}-\d{2}-\d{4}
+ * </pre>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRegularExpressionValidator extends TBaseValidator
+{
+ /**
+ * @return string the regular expression that determines the pattern used to validate a field.
+ */
+ public function getRegularExpression()
+ {
+ return $this->getViewState('RegularExpression','');
+ }
+
+ /**
+ * Sets the regular expression that determines the pattern used to validate a field.
+ * @param string the regular expression
+ */
+ public function setRegularExpression($value)
+ {
+ $this->setViewState('RegularExpression',$value,'');
+ }
+
+ /**
+ * This method overrides the parent's implementation.
+ * The validation succeeds if the input data matches the regular expression.
+ * The validation always succeeds if ControlToValidate is not specified
+ * or the regular expression is empty, or the input data is empty.
+ * @return boolean whether the validation succeeds
+ */
+ public function evaluateIsValid()
+ {
+ if(($control=$this->getValidationTarget())!==null)
+ {
+ if(($value=$this->getValidationValue($control))==='')
+ return true;
+ if(($expression=$this->getRegularExpression())!=='')
+ return preg_match("/^$expression\$/",$value);
+ else
+ return true;
+ }
+ else
+ throw new TInvalidDataValueException('regularexpressionvalidator_controltovalidate_invalid');
+ }
+
+ protected function getClientScriptOptions()
+ {
+ $options = parent::getClientScriptOptions();
+ $options['validationexpression']=$this->getRegularExpression();
+ return $options;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TRequiredFieldValidator.php b/framework/Web/UI/WebControls/TRequiredFieldValidator.php
index b30de607..c937abf8 100644
--- a/framework/Web/UI/WebControls/TRequiredFieldValidator.php
+++ b/framework/Web/UI/WebControls/TRequiredFieldValidator.php
@@ -1,5 +1,29 @@
<?php
+/**
+ * TRequiredFieldValidator class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+/**
+ * Using TBaseValidator class
+ */
+Prado::using('System.Web.UI.WebControls.TBaseValidator');
+
+/**
+ * TRequiredFieldValidator class
+ *
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
class TRequiredFieldValidator extends TBaseValidator
{
public function getInitialValue()
@@ -14,8 +38,13 @@ class TRequiredFieldValidator extends TBaseValidator
protected function evaluateIsValid()
{
- $value=$this->getValidationValue($this->getValidationTarget());
- return trim($value)!==trim($this->getInitialValue());
+ if(($control=$this->getValidationTarget())!==null)
+ {
+ $value=$this->getValidationValue($control);
+ return trim($value)!==trim($this->getInitialValue());
+ }
+ else
+ throw new TInvalidDataValueException('requiredfieldvalidator_controltovalidate_invalid');
}
protected function getClientScriptOptions()
diff --git a/framework/Web/UI/WebControls/TValidationSummary.php b/framework/Web/UI/WebControls/TValidationSummary.php
new file mode 100644
index 00000000..3810901b
--- /dev/null
+++ b/framework/Web/UI/WebControls/TValidationSummary.php
@@ -0,0 +1,405 @@
+<?php
+/**
+ * TValidationSummary class file
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: 1.20 $ $Date: 2005/11/21 07:39:41 $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TValidationSummary class
+ *
+ * TValidationSummary displays a summary of all validation errors inline on a Web page,
+ * in a message box, or both. The summary can be displayed as a list, as a bulleted list,
+ * or as a single paragraph based on the <b>DisplayMode</b> property.
+ * The summary can be displayed on the Web page and in a message box by setting
+ * the <b>ShowSummary</b> and <b>ShowMessageBox</b> properties, respectively.
+ *
+ * Namespace: System.Web.UI.WebControls
+ *
+ * Properties
+ * - <b>DisplayMode</b>, string, default=BulletList, kept in viewstate
+ * <br>Gets or sets the display mode (BulletList, List, SingleParagraph) of the validation summary.
+ * - <b>HeaderText</b>, string, kept in viewstate
+ * <br>Gets or sets the header text displayed at the top of the summary.
+ * - <b>EnableClientScript</b>, boolean, default=true, kept in viewstate
+ * <br>Gets or sets a value indicating whether the TValidationSummary component
+ * updates itself using client-side script.
+ * - <b>ShowMessageBox</b>, boolean, default=false, kept in viewstate
+ * <br>Gets or sets a value indicating whether the validation summary is displayed in a message box.
+ * If <b>EnableClientScript</b> is <b>false</b>, this property has no effect.
+ * - <b>ShowSummary</b>, boolean, default=true, kept in viewstate
+ * <br>Gets or sets a value indicating whether the validation summary is displayed inline.
+ * - <b>Group</b>, string, kept in viewstate
+ * <br>Gets or sets the validation group ID.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version v1.0, last update on 2004/08/13 21:44:52
+ * @package System.Web.UI.WebControls
+ */
+class TValidationSummary extends TWebControl
+{
+
+ protected static $currentGroup;
+
+ public static function setCurrentGroup($group)
+ {
+ self::$currentGroup = $group;
+ }
+
+ public static function getCurrentGroup()
+ {
+ return self::$currentGroup;
+ }
+
+ /**
+ * Overrides parent implementation to disable body addition.
+ * @param mixed the object to be added
+ * @return boolean
+ */
+ public function allowBody($object)
+ {
+ return false;
+ }
+
+ /**
+ * @return string the header text displayed at the top of the summary
+ */
+ public function getHeaderText()
+ {
+ return $this->getViewState('HeaderText','');
+ }
+
+ /**
+ * Sets the header text to be displayed at the top of the summary
+ * @param string the header text
+ */
+ public function setHeaderText($value)
+ {
+ $this->setViewState('HeaderText',$value,'');
+ }
+
+ /**
+ * @return string the display mode (BulletList, List, SingleParagraph) of the validation summary.
+ */
+ public function getDisplayMode()
+ {
+ return $this->getViewState('DisplayMode','BulletList');
+ }
+
+ /**
+ * Sets the display mode (BulletList, List, SingleParagraph) of the validation summary.
+ * @param string the display mode (BulletList, List, SingleParagraph)
+ */
+ public function setDisplayMode($value)
+ {
+ if($value!='List' && $value!='SingleParagraph')
+ $value='BulletList';
+ $this->setViewState('DisplayMode',$value,'BulletList');
+ }
+
+ /**
+ * @return boolean whether the TValidationSummary component updates itself using client-side script.
+ */
+ public function isClientScriptEnabled()
+ {
+ return $this->getViewState('EnableClientScript',true);
+ }
+
+ /**
+ * Sets the value whether the TValidationSummary component updates itself using client-side script.
+ * @param boolean whether the TValidationSummary component updates itself using client-side script.
+ */
+ public function enableClientScript($value)
+ {
+ $this->setViewState('EnableClientScript',$value,true);
+ }
+
+ /**
+ * @return boolean whether the validation summary is displayed in a message box.
+ */
+ public function isShowMessageBox()
+ {
+ return $this->getViewState('ShowMessageBox',false);
+ }
+
+ /**
+ * Sets the value whether the validation summary is displayed in a message box.
+ * @param boolean whether the validation summary is displayed in a message box.
+ */
+ public function setShowMessageBox($value)
+ {
+ $this->setViewState('ShowMessageBox',$value,false);
+ }
+
+ /**
+ * @return boolean whether the validation summary is displayed inline.
+ */
+ public function isShowSummary()
+ {
+ return $this->getViewState('ShowSummary',true);
+ }
+
+ /**
+ * Sets the value whether the validation summary is displayed inline.
+ * @param boolean whether the validation summary is displayed inline.
+ */
+ public function setShowSummary($value)
+ {
+ $this->setViewState('ShowSummary',$value,true);
+ }
+
+ /**
+ * @return boolean whether the validation summary should be anchored.
+ */
+ public function isShowAnchor()
+ {
+ return $this->getViewState('ShowAnchor',false);
+ }
+
+ /**
+ * Sets the value whether the validation summary should be anchored.
+ * @param boolean whether the validation summary should be anchored.
+ */
+ public function setShowAnchor($value)
+ {
+ $this->setViewState('ShowAnchor',$value,false);
+ }
+
+ /**
+ * Gets the valiation group.
+ * @param string validation group ID.
+ */
+ public function getGroup()
+ {
+ return $this->getViewState('Group', '');
+ }
+
+ /**
+ * Sets the validation group.
+ * @param string ID of the validation group.
+ */
+ public function setGroup($value)
+ {
+ $this->setViewState('Group', $value, '');
+ }
+
+ /**
+ * Sets the summary to auto-update on the client-side
+ * @param boolean true for automatic summary updates.
+ */
+ public function setAutoUpdate($value)
+ {
+ $this->setViewState('AutoUpdate', $value, true);
+ }
+
+ /**
+ * Gets the auto-update for this summary.
+ * @return boolean automatic client-side summary updates.
+ */
+ public function isAutoUpdate()
+ {
+ return $this->getViewState('AutoUpdate', true);
+ }
+
+ /**
+ * @return string the group which this validator belongs to
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group which this validator belongs to
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * Get a list of validators considering the validation groups.
+ * @return array list of validators.
+ */
+ protected function getValidators()
+ {
+ $groupID = $this->getGroup();
+ if(empty($groupID)) return $this->getPage()->getValidators();
+
+ $parent = $this->getParent();
+ $group = $parent->findObject($groupID);
+
+ $validators = array();
+
+ foreach($group->getMembers() as $member)
+ {
+ $control = $parent->findObject($member);
+ if(!is_null($control))
+ $validators[] = $control;
+ }
+ return $validators;
+ }
+
+ /**
+ * Render the javascript for validation summary.
+ * @param array list of options for validation summary.
+ */
+ protected function renderJsSummary($options)
+ {
+ if(!$this->isEnabled() || !$this->isClientScriptEnabled())
+ return;
+ $option = TJavascript::toList($options);
+ $script = "new Prado.Validation.Summary({$option});";
+ $this->Page->registerEndScript($this->ClientID, $script);
+ }
+
+ /**
+ * Get a list of options for the client-side javascript validation summary.
+ * @return array list of options for the summary
+ */
+ protected function getJsOptions()
+ {
+ $options['id'] = $this->ClientID;
+ $options['form'] = $this->Page->Form->ClientID;
+ if($this->isShowMessageBox())
+ $options['showmessagebox']='True';
+ if(!$this->isShowSummary())
+ $options['showsummary']='False';
+
+ $options['headertext']=$this->getHeaderText();
+ $options['displaymode']=$this->getDisplayMode();
+
+ $group = $this->getGroup();
+ if(!empty($group))
+ $options['group'] = $this->getParent()->findObject($group)->ClientID;
+
+ $options['refresh'] = $this->isAutoUpdate();
+ $options['validationgroup'] = $this->getValidationGroup();
+ return $options;
+ }
+
+ /**
+ * Get the list of validation error messages.
+ * @return array list of validator error messages.
+ */
+ protected function getMessages()
+ {
+ $validators=$this->getValidators();
+ $messages = array();
+ foreach(array_keys($validators) as $i)
+ {
+ if(!$validators[$i]->isValid())
+ {
+ $msg = $validators[$i]->getErrorMessage();
+ if(strlen($msg))
+ $messages[] = $validators[$i]->getAnchoredMessage($msg);
+ }
+ }
+ return $messages;
+ }
+
+ /**
+ * Overrides parent implementation by rendering TValidationSummary-specific presentation.
+ * @return string the rendering result
+ */
+ public function render()
+ {
+
+ $this->renderJsSummary($this->getJsOptions());
+
+ $content = "";
+ if($this->isRenderSummary())
+ {
+ $this->setStyle('display:block');
+ $messages = $this->getMessages();
+ $headerText = $this->getHeaderText();
+ switch($this->getDisplayMode())
+ {
+ case 'List':
+ $content = $this->renderList($messages, $headerText);
+ break;
+ case 'SingleParagraph':
+ $content = $this->renderSingleParagraph($messages, $headerText);
+ break;
+ case 'BulletList':
+ default:
+ $content = $this->renderBulletList($messages, $headerText);
+ }
+ }
+ return "<div {$this->renderAttributes()}>{$content}</div>";
+ }
+
+ protected function isRenderSummary()
+ {
+ $group = $this->getGroup();
+ $active = TValidatorGroup::isGroupValidation() ? false : true;
+ if(!empty($group))
+ $active = $this->getParent()->findObject($group)->isActive();
+ $render = $this->isEnabled() && $active;
+ $render = $render && !$this->Page->isValid() && $this->isShowSummary();
+ $current = self::getCurrentGroup();
+ if(!is_null($current))
+ $render = $render && $this->getValidationGroup() == $current;
+ return $render;
+ }
+
+ /**
+ * Render the validation summary as a simple list.
+ * @param array list of messages
+ * @param string the header text
+ * @return string summary list
+ */
+ protected function renderList($messages, $header)
+ {
+ $content = '';
+ if(strlen($header))
+ $content.= $header."<br/>\n";
+ foreach($messages as $message)
+ $content.="$message<br/>\n";
+ return $content;
+ }
+
+ /**
+ * Render the validation summary as a paragraph.
+ * @param array list of messages
+ * @param string the header text
+ * @return string summary paragraph
+ */
+ protected function renderSingleParagraph($messages, $header)
+ {
+ $content = $header;
+ foreach($messages as $message)
+ $content.= ' '.$message;
+ return $content;
+ }
+
+ /**
+ * Render the validation summary as a bullet list.
+ * @param array list of messages
+ * @param string the header text
+ * @return string summary bullet list
+ */
+ protected function renderBulletList($messages, $header)
+ {
+ $content = $header;
+ $show = count($messages) > 0;
+ if($show) $content .= "<ul>\n";
+ foreach($messages as $message)
+ $content.= '<li>'.$message."</li>\n";
+ if($show) $content .= "</ul>\n";
+ return $content;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/core.php b/framework/core.php
index 13d8318f..de307cad 100644
--- a/framework/core.php
+++ b/framework/core.php
@@ -771,4 +771,7 @@ class PradoBase
}
}
+class TDate extends TComponent
+{
+}
?> \ No newline at end of file