PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class TBaseValidator

TBaseValidator class

TBaseValidator serves as the base class for validator controls.

Validation is performed when a postback control, such as a TButton, a TLinkButton or a TTextBox (under AutoPostBack mode) is submitting the page and its CausesValidation property is true. You can also manually perform validation by calling TPage::validate(). The input control to be validated is specified by setControlToValidate ControlToValidate.

Validator controls always validate the associated input control on the serve side. In addition, if getEnableClientScript EnableClientScript is true, validation will also be performed on the client-side using javascript. Client-side validation will validate user input before it is sent to the server. The form data will not be submitted if any error is detected. This avoids the round-trip of information necessary for server-side validation.

You can use multiple validator controls to validate a single input control, each responsible for validating against a different criteria. For example, on a user registration form, you may want to make sure the user enters a value in the username text box, and the input must consist of only word characters. You can use a TRequiredFieldValidator to ensure the input of username and a TRegularExpressionValidator to ensure the proper input.

If an input control fails validation, the text specified by the setErrorMessage ErrorMessage property is displayed in the validation control. However, if the setText Text property is set, it will be displayed instead. If both setErrorMessage ErrorMessage and setText Text are empty, the body content of the validator will be displayed. Error display is controlled by setDisplay Display property.

You can also customized the client-side behaviour by adding javascript code to the subproperties of the getClientSide ClientSide property. See quickstart documentation for further details.

You can also place a TValidationSummary control on a page to display error messages from the validators together. In this case, only the setErrorMessage ErrorMessage property of the validators will be displayed in the TValidationSummary control.

Validators can be partitioned into validation groups by setting their setValidationGroup ValidationGroup property. If the control causing the validation also sets its ValidationGroup property, only those validators having the same ValidationGroup value will do input validation.

Note, the TPage::getIsValid IsValid property of the current TPage instance will be automatically updated by the validation process which occurs after TPage::onLoad onLoad of TPage and before the postback events. Therefore, if you use the TPage::getIsValid() property in the TControl::onLoad() method, you must first explicitly call the TPage::validate() method.

Notes to Inheritors When you inherit from TBaseValidator, you must override the method TBaseValidator::evaluateIsValid().

TComponent
Extended by TApplicationComponent
Extended by TControl implements IRenderable, IBindable
Extended by TWebControl implements IStyleable
Extended by TLabel implements IDataRenderer
Extended by TBaseValidator implements IValidator

Direct known subclasses

TCaptchaValidator, TCompareValidator, TCustomValidator, TDataTypeValidator, TListControlValidator, TRangeValidator, TReCaptchaValidator, TRegularExpressionValidator, TRequiredFieldValidator

Indirect known subclasses

TActiveCustomValidator, TEmailAddressValidator
Abstract
Package: System\Web\UI\WebControls
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Web/UI/WebControls/TBaseValidator.php
Methods summary
public
# __construct( )

Constructor. This method sets the foreground color to red.

Constructor. This method sets the foreground color to red.

Overrides

TControl::__construct()
public
# onInit( mixed $param )

Registers the validator with page.

Registers the validator with page.

Parameters

$param
mixed
event parameter

Overrides

TControl::onInit()
public
# onUnload( mixed $param )

Unregisters the validator from page.

Unregisters the validator from page.

Parameters

$param
mixed
event parameter

Overrides

TControl::onUnload()
protected
# addAttributesToRender( THtmlWriter $writer )

Adds attributes to renderer. Calls parent implementation and renders the client control scripts.

Adds attributes to renderer. Calls parent implementation and renders the client control scripts.

Parameters

$writer
THtmlWriter
the renderer

Throws

TInvalidDataValueException
if associated control cannot be found using the ID

Overrides

TLabel::addAttributesToRender()
protected array
# getClientScriptOptions( )

Returns an array of javascript validator options.

Returns an array of javascript validator options.

Returns

array
javascript validator options.
public TValidatorClientSide
# getClientSide( )

Gets the TValidatorClientSide that allows modification of the client- side validator events.

Gets the TValidatorClientSide that allows modification of the client- side validator events.

The client-side validator supports the following events. # OnValidate -- raised before client-side validation is executed. # OnValidationSuccess -- raised after client-side validation is completed and is successfull, overrides default validator error messages updates. # OnValidationError -- raised after client-side validation is completed and failed, overrides default validator error message updates.

You can attach custom javascript code to each of these events

Returns

TValidatorClientSide
javascript validator event options.
protected TValidatorClientSide
# createClientSide( )

Returns

TValidatorClientSide
javascript validator event options.
public
# renderClientControlScript( THtmlWriter $writer )

Renders the javascript code to the end script. If you override this method, be sure to call the parent implementation so that the event handlers can be invoked.

Renders the javascript code to the end script. If you override this method, be sure to call the parent implementation so that the event handlers can be invoked.

Parameters

$writer
THtmlWriter
the renderer
public
# onPreRender( TEventParameter $param )

Override parent implementation to update the control CSS Class before the validated control is rendered

Override parent implementation to update the control CSS Class before the validated control is rendered

Parameters

$param
TEventParameter
event parameter to be passed to the event handlers

Overrides

TWebControl::onPreRender()
protected boolean
# updateControlCssClass( )

Update the ControlToValidate component's css class depending if the ControlCssClass property is set, and whether this is valid.

Update the ControlToValidate component's css class depending if the ControlCssClass property is set, and whether this is valid.

Returns

boolean
true if change, false otherwise.
protected
# registerClientScriptValidator( )

Registers the individual validator client-side javascript code.

Registers the individual validator client-side javascript code.

abstract protected string
# getClientClassName( )

Gets the name of the javascript class responsible for performing validation for this control. This method overrides the parent implementation.

Gets the name of the javascript class responsible for performing validation for this control. This method overrides the parent implementation.

Returns

string
the javascript class name
public
# setForControl( string $value )

This method overrides the parent implementation to forbid setting ForControl.

This method overrides the parent implementation to forbid setting ForControl.

Parameters

$value
string
the associated control ID

Throws

TNotSupportedException
whenever this method is called

Overrides

TLabel::setForControl()
public
# setEnabled( boolean $value )

This method overrides parent's implementation by setting setIsValid IsValid to true if disabled.

This method overrides parent's implementation by setting setIsValid IsValid to true if disabled.

Parameters

$value
boolean
whether the validator is enabled.

Overrides

TControl::setEnabled()
public TValidatorDisplayStyle
# getDisplay( )

Returns

TValidatorDisplayStyle
the style of displaying the error message. Defaults to TValidatorDisplayStyle::Fixed.

Overrides

TWebControl::getDisplay()
public
# setDisplay( TValidatorDisplayStyle $value )

Parameters

$value
TValidatorDisplayStyle
the style of displaying the error message

Overrides

TWebControl::setDisplay()
public boolean
# getEnableClientScript( )

Returns

boolean
whether client-side validation is enabled.
public
# setEnableClientScript( boolean $value )

Parameters

$value
boolean
whether client-side validation is enabled.
public string
# getErrorMessage( )

Returns

string
the text for the error message.

Implementation of

IValidator::getErrorMessage()
public
# setErrorMessage( string $value )

Sets the text for the error message.

Sets the text for the error message.

Parameters

$value
string
the error message

Implementation of

IValidator::setErrorMessage()
public string
# getControlToValidate( )

Returns

string
the ID path of the input control to validate
public
# setControlToValidate( string $value )

Sets the ID path of the input control to validate. The ID path is the dot-connected IDs of the controls reaching from the validator's naming container to the target control.

Sets the ID path of the input control to validate. The ID path is the dot-connected IDs of the controls reaching from the validator's naming container to the target control.

Parameters

$value
string
the ID path
public boolean
# getFocusOnError( )

Returns

boolean
whether to set focus at the validating place if the validation fails. Defaults to false.
public
# setFocusOnError( boolean $value )

Parameters

$value
boolean
whether to set focus at the validating place if the validation fails
public string
# getFocusElementID( )

Gets the ID of the HTML element that will receive focus if validation fails and getFocusOnError FocusOnError is true. Defaults to the client ID of the getControlToValidate ControlToValidate.

Gets the ID of the HTML element that will receive focus if validation fails and getFocusOnError FocusOnError is true. Defaults to the client ID of the getControlToValidate ControlToValidate.

Returns

string
the ID of the HTML element to receive focus
public
# setFocusElementID( string $value )

Sets the ID of the HTML element that will receive focus if validation fails and getFocusOnError FocusOnError is true.

Sets the ID of the HTML element that will receive focus if validation fails and getFocusOnError FocusOnError is true.

Parameters

$value
string
the ID of the HTML element to receive focus
public string
# getValidationGroup( )

Returns

string
the group which this validator belongs to
public
# setValidationGroup( string $value )

Parameters

$value
string
the group which this validator belongs to
public boolean
# getIsValid( )

Returns

boolean
whether the validation succeeds

Implementation of

IValidator::getIsValid()
public
# setIsValid( boolean $value )

Sets the value indicating whether the validation succeeds

Sets the value indicating whether the validation succeeds

Parameters

$value
boolean
whether the validation succeeds

Implementation of

IValidator::setIsValid()
public TControl
# getValidationTarget( )

Returns

TControl
control to be validated. Null if no control is found.

Throws

TConfigurationException
if getControlToValidate ControlToValidate is empty or does not point to a valid control
protected string
# getValidationValue( TControl $control )

Retrieves the property value of the control being validated.

Retrieves the property value of the control being validated.

Parameters

$control
TControl
control being validated

Returns

string
property value to be validated

Throws

TInvalidDataTypeException
if the control to be validated does not implement IValidatable.
public boolean
# validate( )

Validates the specified control. Do not override this method. Override TBaseValidator::evaluateIsValid() instead.

Validates the specified control. Do not override this method. Override TBaseValidator::evaluateIsValid() instead.

Returns

boolean
whether the validation succeeds

Implementation of

IValidator::validate()
public string
# getControlCssClass( )

Returns

string
the css class that is applied to the control being validated in case the validation fails
public
# setControlCssClass( string $value )

Parameters

$value
string
the css class that is applied to the control being validated in case the validation fails
abstract protected boolean
# evaluateIsValid( )

This is the major method for validation. Derived classes should implement this method to provide customized validation.

This is the major method for validation. Derived classes should implement this method to provide customized validation.

Returns

boolean
whether the validation succeeds
public
# onValidationSuccess( )

This event is raised when the validator succeeds in validation.

This event is raised when the validator succeeds in validation.

public
# onValidationError( )

This event is raised when the validator fails in validation.

This event is raised when the validator fails in validation.

public
# onValidate( )

This event is raised right before the validator starts to perform validation. You may use this event to change the behavior of validation. For example, you may disable the validator if certain condition is satisfied. Note, the event will NOT be raised if the validator is invisible.

This event is raised right before the validator starts to perform validation. You may use this event to change the behavior of validation. For example, you may disable the validator if certain condition is satisfied. Note, the event will NOT be raised if the validator is invisible.

public
# renderContents( THtmlWriter $writer )

Renders the validator control.

Renders the validator control.

Parameters

$writer
THtmlWriter
writer for the rendering purpose

Overrides

TLabel::renderContents()
Methods inherited from TLabel
getData(), getForControl(), getTagName(), getText(), render(), setData(), setText()
Methods inherited from TWebControl
clearStyle(), copyBaseAttributes(), createStyle(), getAccessKey(), getBackColor(), getBorderColor(), getBorderStyle(), getBorderWidth(), getCssClass(), getDecorator(), getEnsureId(), getFont(), getForeColor(), getHasStyle(), getHeight(), getStyle(), getTabIndex(), getToolTip(), getWidth(), renderBeginTag(), renderEndTag(), setAccessKey(), setBackColor(), setBorderColor(), setBorderStyle(), setBorderWidth(), setCssClass(), setEnsureId(), setForeColor(), setHeight(), setStyle(), setTabIndex(), setToolTip(), setWidth()
Methods inherited from TControl
__get(), addParsedObject(), addToPostDataLoader(), addedControl(), applyStyleSheetSkin(), autoBindProperty(), autoDataBindProperties(), bindProperty(), broadcastEvent(), bubbleEvent(), clearChildState(), clearControlState(), clearNamingContainer(), clearViewState(), convertUniqueIdToClientId(), createChildControls(), createControlCollection(), dataBind(), dataBindChildren(), dataBindProperties(), ensureChildControls(), findControl(), findControlsByID(), findControlsByType(), focus(), getAdapter(), getAllowChildControls(), getAttribute(), getAttributes(), getChildControlsCreated(), getClientID(), getControlStage(), getControlState(), getControls(), getCustomData(), getEnableTheming(), getEnableViewState(), getEnabled(), getHasAdapter(), getHasAttributes(), getHasChildInitialized(), getHasControls(), getHasInitialized(), getHasLoaded(), getHasLoadedPostData(), getHasPreRendered(), getID(), getIsSkinApplied(), getNamingContainer(), getPage(), getParent(), getRegisteredObject(), getSkinID(), getSourceTemplateControl(), getTemplateControl(), getUniqueID(), getViewState(), getVisible(), hasAttribute(), initRecursive(), isDescendentOf(), isObjectRegistered(), loadRecursive(), loadState(), loadStateRecursive(), onDataBinding(), onLoad(), preRenderRecursive(), raiseBubbleEvent(), registerObject(), removeAttribute(), removedControl(), renderChildren(), renderControl(), saveState(), saveStateRecursive(), setAdapter(), setAttribute(), setChildControlsCreated(), setControlStage(), setControlState(), setCustomData(), setEnableTheming(), setEnableViewState(), setID(), setPage(), setSkinID(), setTemplateControl(), setViewState(), setVisible(), trackViewState(), traverseChildControls(), unbindProperty(), unloadRecursive(), unregisterObject()
Methods inherited from TApplicationComponent
getApplication(), getRequest(), getResponse(), getService(), getSession(), getUser(), publishAsset(), publishFilePath()
Methods inherited from TComponent
__call(), __destruct(), __isset(), __set(), __sleep(), __unset(), __wakeup(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants inherited from TControl
AUTOMATIC_ID_PREFIX, CLIENT_ID_SEPARATOR, CS_CHILD_INITIALIZED, CS_CONSTRUCTED, CS_INITIALIZED, CS_LOADED, CS_PRERENDERED, CS_STATE_LOADED, ID_FORMAT, ID_SEPARATOR, IS_CHILD_CREATED, IS_CREATING_CHILD, IS_DISABLE_THEMING, IS_DISABLE_VIEWSTATE, IS_ID_SET, IS_SKIN_APPLIED, IS_STYLESHEET_APPLIED, RF_ADAPTER, RF_AUTO_BINDINGS, RF_CHILD_STATE, RF_CONTROLS, RF_CONTROLSTATE, RF_DATA_BINDINGS, RF_EVENTS, RF_NAMED_CONTROLS, RF_NAMED_CONTROLS_ID, RF_NAMED_OBJECTS, RF_SKIN_ID
Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Properties inherited from TWebControl
$_decorator
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO