summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2006-01-16 22:22:39 +0000
committerxue <>2006-01-16 22:22:39 +0000
commit473e29dfcec480bd146bc31e42f0f9438b7210f9 (patch)
tree033dfe5c923446ae1178b9af596b274cf067bc13
parent318ca1a7cc0085f36a6ca6648b6b2a7eb2bab295 (diff)
Added validation examples.
-rw-r--r--.gitattributes5
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.page42
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.php8
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TValidationSummary/Home.page25
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TValidationSummary/Home.php8
-rw-r--r--demos/quickstart/protected/pages/Controls/Validation.page5
-rw-r--r--framework/Web/UI/WebControls/TCompareValidator.php1
-rw-r--r--framework/Web/UI/WebControls/TEmailAddressValidator.php60
-rw-r--r--framework/Web/UI/WebControls/TValidationSummary.php179
9 files changed, 214 insertions, 119 deletions
diff --git a/.gitattributes b/.gitattributes
index 780ca90a..806aa5d8 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -44,6 +44,8 @@ demos/quickstart/protected/pages/Controls/Samples/TBulletedList/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TBulletedList/bullet.gif -text
demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.php -text
+demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.page -text
+demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TCustomValidator/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TCustomValidator/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample1.page -text
@@ -68,6 +70,8 @@ demos/quickstart/protected/pages/Controls/Samples/TTable/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TTable/backimage.gif -text
demos/quickstart/protected/pages/Controls/Samples/TTextBox/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TTextBox/Home.php -text
+demos/quickstart/protected/pages/Controls/Samples/TValidationSummary/Home.page -text
+demos/quickstart/protected/pages/Controls/Samples/TValidationSummary/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/config.xml -text
demos/quickstart/protected/pages/Controls/Simple.page -text
demos/quickstart/protected/pages/Controls/Validation.page -text
@@ -538,6 +542,7 @@ framework/Web/UI/WebControls/TDataSourceControl.php -text
framework/Web/UI/WebControls/TDataSourceView.php -text
framework/Web/UI/WebControls/TDropDownList.php -text
framework/Web/UI/WebControls/TEditCommandColumn.php -text
+framework/Web/UI/WebControls/TEmailAddressValidator.php -text
framework/Web/UI/WebControls/TExpression.php -text
framework/Web/UI/WebControls/TFileUpload.php -text
framework/Web/UI/WebControls/TFont.php -text
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.page
new file mode 100644
index 00000000..7abed86a
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.page
@@ -0,0 +1,42 @@
+<com:TContent ID="body">
+
+<h1>TCompareValidator Samples</h1>
+
+<table class="sampletable">
+
+<tr>
+<td class="samplenote">
+Compare validator with default settings:
+</td>
+<td class="sampleaction">
+<com:TTextBox ID="TextBox1" />
+<com:TTextBox ID="TextBox11" />
+<com:TCompareValidator
+ ValidationGroup="Group1"
+ ControlToValidate="TextBox1"
+ ControlToCompare="TextBox11"
+ Text="The two textboxes must have the same value." />
+<com:TButton Text="Submit" ValidationGroup="Group1" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Compare validator with client-side validation disabled:
+</td>
+<td class="sampleaction">
+<com:TTextBox ID="TextBox2" />
+<com:TTextBox ID="TextBox22" />
+<com:TCompareValidator
+ ValidationGroup="Group2"
+ EnableClientScript="false"
+ ControlToValidate="TextBox2"
+ ControlToCompare="TextBox22"
+ Text="The two textboxes must have the same value." />
+<com:TButton Text="Submit" ValidationGroup="Group2" />
+</td>
+</tr>
+
+</table>
+
+</com:TContent> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.php
new file mode 100644
index 00000000..88d2dbf2
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/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/TValidationSummary/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TValidationSummary/Home.page
new file mode 100644
index 00000000..75ca9c52
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TValidationSummary/Home.page
@@ -0,0 +1,25 @@
+<com:TContent ID="body">
+
+<h1>TValidationSummary Samples</h1>
+
+<table class="sampletable">
+
+<tr>
+<td class="samplenote">
+Required field validator with default settings:
+</td>
+<td class="sampleaction">
+<com:TValidationSummary ValidationGroup="Group1" />
+<com:TTextBox ID="TextBox1" />
+<com:TRequiredFieldValidator
+ ValidationGroup="Group1"
+ ControlToValidate="TextBox1"
+ Text="Field required." />
+<com:TButton Text="Submit" ValidationGroup="Group1" />
+</td>
+</tr>
+
+
+</table>
+
+</com:TContent> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TValidationSummary/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TValidationSummary/Home.php
new file mode 100644
index 00000000..88d2dbf2
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TValidationSummary/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/Validation.page b/demos/quickstart/protected/pages/Controls/Validation.page
index b0bf46e1..f37df4d6 100644
--- a/demos/quickstart/protected/pages/Controls/Validation.page
+++ b/demos/quickstart/protected/pages/Controls/Validation.page
@@ -32,4 +32,9 @@
</p>
<com:RunBar PagePath="Controls.Samples.TCustomValidator.Home" />
+<h2>TValidationSummary</h2>
+<p>
+</p>
+<com:RunBar PagePath="Controls.Samples.TValidationSummary.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
index b7363792..cfc2e876 100644
--- a/framework/Web/UI/WebControls/TCompareValidator.php
+++ b/framework/Web/UI/WebControls/TCompareValidator.php
@@ -235,6 +235,7 @@ class TCompareValidator extends TBaseValidator
$value2=0;
return array($value1, $value2);
case 'Date':
+ throw new TNotSupportedException('Date comparison for TCompareValidator is currently not supported. It will be supported in future.');
$dateFormat = $this->getDateFormat();
if (strlen($dateFormat))
return array(pradoParseDate($value1, $dateFormat), pradoParseDate($value2, $dateFormat));
diff --git a/framework/Web/UI/WebControls/TEmailAddressValidator.php b/framework/Web/UI/WebControls/TEmailAddressValidator.php
new file mode 100644
index 00000000..48516c44
--- /dev/null
+++ b/framework/Web/UI/WebControls/TEmailAddressValidator.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * TEmailAddressValidator 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 TRegularExpressionValidator class
+ */
+Prado::using('System.Web.UI.WebControls.TRegularExpressionValidator');
+
+/**
+ * TEmailAddressValidator class
+ *
+ * TEmailAddressValidator validates whether the value of an associated
+ * input component is a valid email address. It will check MX record
+ * if checkdnsrr() is implemented.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TEmailAddressValidator extends TRegularExpressionValidator
+{
+ const EMAIL_REGEXP="\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
+
+ public function getRegularExpression()
+ {
+ $regex=parent::getRegularExpression();
+ return $regex===''?self::EMAIL_REGEXP:$regex;
+ }
+
+ public function evaluateIsValid()
+ {
+ $valid=parent::evaluateIsValid();
+ if($valid && function_exists('checkdnsrr'))
+ {
+ if(($value=$this->getValidationValue($this->getValidationTarget()))!=='')
+ {
+ if(($pos=strpos($value,'@'))!==false)
+ {
+ $domain=substr($value,$pos+1);
+ return $domain===''?false:checkdnsrr($domain,'MX');
+ }
+ else
+ return false;
+ }
+ }
+ return $valid;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TValidationSummary.php b/framework/Web/UI/WebControls/TValidationSummary.php
index 3810901b..14cf869d 100644
--- a/framework/Web/UI/WebControls/TValidationSummary.php
+++ b/framework/Web/UI/WebControls/TValidationSummary.php
@@ -2,17 +2,11 @@
/**
* 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 $
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
*/
@@ -44,8 +38,9 @@
* <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
+ * @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
+ * @since 3.0
*/
class TValidationSummary extends TWebControl
{
@@ -62,15 +57,6 @@ class TValidationSummary extends TWebControl
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
@@ -90,7 +76,7 @@ class TValidationSummary extends TWebControl
}
/**
- * @return string the display mode (BulletList, List, SingleParagraph) of the validation summary.
+ * @return string the display mode (BulletList, List, SingleParagraph) of the validation summary. Defaults to BulletList.
*/
public function getDisplayMode()
{
@@ -103,95 +89,80 @@ class TValidationSummary extends TWebControl
*/
public function setDisplayMode($value)
{
- if($value!='List' && $value!='SingleParagraph')
- $value='BulletList';
- $this->setViewState('DisplayMode',$value,'BulletList');
+ $this->setViewState('DisplayMode',TPropertyValue::ensureEnum($value,'List','SingleParagraph','BulletList'),'BulletList');
}
/**
- * @return boolean whether the TValidationSummary component updates itself using client-side script.
+ * @return boolean whether the TValidationSummary component updates itself using client-side script. Defaults to true.
*/
- public function isClientScriptEnabled()
+ public function getEnableClientScript()
{
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)
+ public function setEnableClientScript($value)
{
- $this->setViewState('EnableClientScript',$value,true);
+ $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
}
/**
- * @return boolean whether the validation summary is displayed in a message box.
+ * @return boolean whether the validation summary is displayed in a message box. Defaults to false.
*/
- public function isShowMessageBox()
+ public function getShowMessageBox()
{
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);
+ $this->setViewState('ShowMessageBox',TPropertyValue::ensureBoolean($value),false);
}
/**
- * @return boolean whether the validation summary is displayed inline.
+ * @return boolean whether the validation summary is displayed inline. Defaults to true.
*/
- public function isShowSummary()
+ public function getShowSummary()
{
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);
+ $this->setViewState('ShowSummary',TPropertyValue::ensureBoolean($value),true);
}
/**
- * @return boolean whether the validation summary should be anchored.
+ * @return boolean whether the validation summary should be anchored. Defaults to false.
*/
- public function isShowAnchor()
+ public function getShowAnchor()
{
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);
+ $this->setViewState('ShowAnchor',TPropertyValue::ensureBoolean($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.
+ * Gets the auto-update for this summary.
+ * @return boolean automatic client-side summary updates. Defaults to true.
*/
- public function setGroup($value)
+ public function getAutoUpdate()
{
- $this->setViewState('Group', $value, '');
+ return $this->getViewState('AutoUpdate', true);
}
/**
@@ -200,16 +171,7 @@ class TValidationSummary extends TWebControl
*/
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);
+ $this->setViewState('AutoUpdate', TPropertyValue::ensureBoolean($value), true);
}
/**
@@ -255,36 +217,32 @@ class TValidationSummary extends TWebControl
* Render the javascript for validation summary.
* @param array list of options for validation summary.
*/
- protected function renderJsSummary($options)
+ protected function renderJsSummary()
{
- if(!$this->isEnabled() || !$this->isClientScriptEnabled())
+ if(!$this->getEnabled(true) || !$this->getEnableClientScript())
return;
- $option = TJavascript::toList($options);
- $script = "new Prado.Validation.Summary({$option});";
- $this->Page->registerEndScript($this->ClientID, $script);
+ $options = TJavascript::toList($this->getClientScriptOptions());
+ $script = "new Prado.Validation.Summary({$options});";
+ $this->getPage()->getClientScript()->registerEndScript($this->getClientID(), $script);
}
/**
* Get a list of options for the client-side javascript validation summary.
* @return array list of options for the summary
*/
- protected function getJsOptions()
+ protected function getClientScriptOptions()
{
$options['id'] = $this->ClientID;
$options['form'] = $this->Page->Form->ClientID;
- if($this->isShowMessageBox())
+ if($this->getShowMessageBox())
$options['showmessagebox']='True';
- if(!$this->isShowSummary())
+ if(!$this->getShowSummary())
$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['refresh'] = $this->getAutoUpdate();
$options['validationgroup'] = $this->getValidationGroup();
return $options;
}
@@ -293,18 +251,15 @@ class TValidationSummary extends TWebControl
* Get the list of validation error messages.
* @return array list of validator error messages.
*/
- protected function getMessages()
+ protected function getErrorMessages()
{
- $validators=$this->getValidators();
+ $validators=$this->getPage()->getValidators($this->getValidationGroup());
$messages = array();
- foreach(array_keys($validators) as $i)
+ foreach($validators as $validator)
{
- if(!$validators[$i]->isValid())
- {
- $msg = $validators[$i]->getErrorMessage();
- if(strlen($msg))
- $messages[] = $validators[$i]->getAnchoredMessage($msg);
- }
+ if(!$validator->getIsValid() && ($msg=$validator->getErrorMessage())!=='')
+ //$messages[] = $validator->getAnchoredMessage($msg);
+ $messages[] = $msg;
}
return $messages;
}
@@ -313,45 +268,25 @@ class TValidationSummary extends TWebControl
* Overrides parent implementation by rendering TValidationSummary-specific presentation.
* @return string the rendering result
*/
- public function render()
+ protected function renderContents($writer)
{
-
- $this->renderJsSummary($this->getJsOptions());
-
- $content = "";
- if($this->isRenderSummary())
+ $this->renderJsSummary();
+ if($this->getShowSummary())
{
- $this->setStyle('display:block');
- $messages = $this->getMessages();
- $headerText = $this->getHeaderText();
+// $this->setStyle('display:block');
switch($this->getDisplayMode())
{
case 'List':
- $content = $this->renderList($messages, $headerText);
+ $content = $this->renderList($writer);
break;
case 'SingleParagraph':
- $content = $this->renderSingleParagraph($messages, $headerText);
+ $content = $this->renderSingleParagraph($writer);
break;
case 'BulletList':
default:
- $content = $this->renderBulletList($messages, $headerText);
+ $content = $this->renderBulletList($writer);
}
}
- 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;
}
/**
@@ -360,14 +295,16 @@ class TValidationSummary extends TWebControl
* @param string the header text
* @return string summary list
*/
- protected function renderList($messages, $header)
+ protected function renderList($writer)
{
+ $header=$this->getHeaderText();
+ $messages=$this->getErrorMessages();
$content = '';
if(strlen($header))
$content.= $header."<br/>\n";
foreach($messages as $message)
$content.="$message<br/>\n";
- return $content;
+ $writer->write($content);
}
/**
@@ -376,12 +313,14 @@ class TValidationSummary extends TWebControl
* @param string the header text
* @return string summary paragraph
*/
- protected function renderSingleParagraph($messages, $header)
+ protected function renderSingleParagraph($writer)
{
+ $header=$this->getHeaderText();
+ $messages=$this->getErrorMessages();
$content = $header;
foreach($messages as $message)
$content.= ' '.$message;
- return $content;
+ $writer->write($content);
}
/**
@@ -390,15 +329,17 @@ class TValidationSummary extends TWebControl
* @param string the header text
* @return string summary bullet list
*/
- protected function renderBulletList($messages, $header)
+ protected function renderBulletList($writer)
{
+ $header=$this->getHeaderText();
+ $messages=$this->getErrorMessages();
$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;
+ $writer->write($content);
}
}