phpDocumentor SForm
Rules
[ class tree: SForm ] [ index: SForm ] [ all elements ]

Class: SForm_Rule_Boolean

Source Location: /SForm/Rule/Boolean.php

Class SForm_Rule_Boolean

Class Overview

Used to generate on-the-fly boolean rules

This is a completely free form boolean statement, with an arbitrary number of elements used. It automatically uses the boolean statement to generate code for both client side and server side validation.

This means that you can easily create complex rules, such as validating a credit card number depnding on which type of credit card is selected. You can require a user to fill in identifying information if they don't have a user name. You can better control filling out billing vs. shipping information. You can also do any of this in JavaScript.

Example:

If the text input is blank and the value -2 is selected in the pull down menu, throw an error:

  1.  $newNameElm->addRule'boolean''%s == "" && %s == -2',
  2.                  array($newNameElm$areaElm),
  3.                  'If you are creating a new area, you must fill in it\'s name.' );

Located in /SForm/Rule/Boolean.php [line 65]

SForm_Rule
   |
   --SForm_Rule_Boolean

Properties

Methods

[ Top ]
Inherited Properties, Constants, and Methods
Inherited Properties Inherited Methods Inherited Constants

Inherited From SForm_Rule

SForm_Rule::$elements
SForm_Rule::$hasParent
SForm_Rule::$jsElmNum
SForm_Rule::$jsElmVar
SForm_Rule::$message
SForm_Rule::$validateOnClient

Inherited From SForm_Rule

SForm_Rule::__construct()
Construct a rule with one element and one error message
SForm_Rule::assignParent()
Mark this rule as having a parent
SForm_Rule::createJSRule()
Create a basic if-then rule in JavaScript
SForm_Rule::escClient()
Escape client side variables
SForm_Rule::genJSValue()
Returns JS to get a value and save it in the local variable
SForm_Rule::isError()
Returns true if this element(s) fail validation
SForm_Rule::toJavaScript()
Get the JavaScript that should be run onsubmit
SForm_Rule::toString()
Returns a message describing the error and its cause
SForm_Rule::validateOnClient()
Should we run validation code on the client

[ Top ]
Property Summary
string   $freeFormBool   Define this rule

[ Top ]
Method Summary
SForm_Rule_Boolean   __construct()   Create a free form boolean rule
boolean   isError()   Does the statement evaluate to true?
string   toJavaScript()   Generates JS that will execute the boolean statement

[ Top ]
Properties
string   $freeFormBool [line 72]

Define this rule

API Tags:
Access:  protected


[ Top ]
Methods
Constructor __construct  [line 91]

  SForm_Rule_Boolean __construct( string $message, array $elements, string $freeFormBool  )

Create a free form boolean rule

The first arg is the messsage that will be returned when an error ocours.

The second arg are the elements who's values will be fed into the boolean statement.

Last argument is a boolean string, with vars like http://www.php.net/sprintf would accept. The placeholders in the string should be '%s' so we can insert the required text into it. The boolean string should evaluate to true iff there is an error.

Parameters:
string   $message:  Error message
array   $elements:  The elements used by the statement
string   $freeFormBool:  Boolean statement


Redefinition of:
SForm_Rule::__construct()
Construct a rule with one element and one error message

[ Top ]
isError  [line 128]

  boolean isError( )

Does the statement evaluate to true?

Values are found for each of the input elements, php code is created using those values, and the whole thing is fed through eval() to produce a boolean value.


API Tags:
Return:  Evaluation of the boolean statement
Access:  public


Redefinition of:
SForm_Rule::isError()
Returns true if this element(s) fail validation

[ Top ]
toJavaScript  [line 159]

  string toJavaScript( )

Generates JS that will execute the boolean statement

The code to locate the value of each element is created with the necessary local variables and the local variables are parsed into the boolean string. The strings are then inserted in the appropriate points in JS to throw an error if the boolean statement evaluated as true.


API Tags:
Return:  JavaScript
Access:  public


Redefinition of:
SForm_Rule::toJavaScript()
Get the JavaScript that should be run onsubmit

[ Top ]

Documentation generated on Mon, 09 Apr 2007 19:06:37 -0500 by phpDocumentor 1.3.0