XCube
The foundational Core of XoopsCube Legacy
 
Loading...
Searching...
No Matches
XCube_ActionForm Class Reference

Public Member Functions

 __construct ()
 Constructor.
 
 prepare ()
 [Abstract] Set up form properties and field properties.
 
 getTokenName ()
 Gets the token name of this actionform's token.
 
 getToken ()
 Gets the token value of this actionform's token.
 
 getTokenErrorMessage ()
 Gets a message about the failure of the token validation.
 
 set ()
 Sets the raw value as the value of the form property.
 
 setVar ()
 
 get ( $key, $index=null)
 Gets raw value.
 
 getVar ( $key, $index=null)
 
getFormProperties ()
 Gets form properties of this member property.
 
 fetch ()
 Fetches values through the request object.
 
 _validateToken ()
 Validates the token.
 
 validate ()
 Validates fetched values.
 
 hasError ()
 Gets a value indicating whether this action form keeps error messages or error flag.
 
 addErrorMessage ( $message)
 Adds a message to the form's error message buffer.
 
 getErrorMessages ()
 Gets error messages.
 
 load (&$obj)
 [Abstract] Initializes properties' values from an object.
 
 update (&$obj)
 [Abstract] Updates an object with properties values.
 

Data Fields

 $mContext
 [READ ONLY] XCube_HttpContext
 
 $mUser
 [READ ONLY] XCube_Principal
 
 $mFormProperties = []
 XCube_FormProperty[].
 
 $mFieldProperties = []
 XCube_FieldProperty[].
 
 $mErrorFlag = false
 bool
 
 $mErrorMessages = []
 string[]
 
 $_mToken
 string
 

Member Function Documentation

◆ _validateToken()

_validateToken ( )

Validates the token.

Returns
void

Validates the token. This method is deprecated, because XCube_Action will be changed for multi-layer. So this method is called only by this class.

Todo
This method has to be remove, because it is using session directly.

◆ addErrorMessage()

addErrorMessage ( $message)

Adds a message to the form's error message buffer.

Parameters
string$message

◆ fetch()

fetch ( )

Fetches values through the request object.

Returns
void
See also
getFromRequest

Fetch the input value, set it and form properties. These values can be retrieved by the get() method. The subclass can define its own member function to fetch the values. Define member functions with name "fetch" + "form name". For example, to fetch the "message", define the function "fetchMessage()". The subclass function assigns a value to this action form.

function fetchModifytime()
{
$this->set('modifytime', time());
}

◆ get()

get ( $key,
$index = null )

Gets raw value.

Parameters
string$keyName of form property.
string$indexHint for array.
Returns
mixed
Attention
This method returns raw values. Therefore, if the value is used in templates, it should require an escape.

◆ getErrorMessages()

getErrorMessages ( )

Gets error messages.

Returns
string[]

◆ getFormProperties()

& getFormProperties ( )

Gets form properties of this member property.

Returns
XCube_AbstractProperty[]
Attention
This method is Not necessarily essential. It could be renamed in the near future.
Todo
Check whether this method is needed.

◆ getToken()

getToken ( )

Gets the token value of this actionform's token.

Returns
string

Generates a token value, stores it in sessions, returns it. This member function should be called in templates. A subclass can override it to modify the logic generating the token value.

◆ getTokenErrorMessage()

getTokenErrorMessage ( )

Gets a message about the failure of the token validation.

Returns
string

◆ getTokenName()

getTokenName ( )

Gets the token name of this actionform's token.

Returns
string

Return token name. If the sub-class doesn't override this member function, features about one-time tokens aren't used.

◆ getVar()

getVar ( $key,
$index = null )
Parameters
$key
null$index
Returns
mixed
Deprecated

◆ hasError()

hasError ( )

Gets a value indicating whether this action form keeps error messages or error flag.

Returns
bool - If the action form is error status, returns true.

◆ load()

load ( & $obj)

[Abstract] Initializes properties' values from an object.

Parameters
mixed$obj
Returns
void

Set the initial values of this Action Form from an object. This member function mediates between logic and validation. For example, developers can use this method to load values from XoopsSimpleObject.

This member function is abstract. But, the subclass of this class does not have to implement it.

◆ set()

set ( )

Sets the raw value as the value of the form property.

This method is an overloaded function.

XCube_ActionForm::set($name, $value)
Set $value to $name property.
$this->set('name', 'Bob'); // Set 'Bob' to 'name'.
XCube_ActionForm::set($name, $index, $value)
Set $value to $name array property[$index].
$this->set('names', 0, 'Bob'); // Set 'Bob' to 'names[0]'.

◆ setVar()

setVar ( )

◆ update()

update ( & $obj)

[Abstract] Updates an object with properties values.

Parameters
mixed$obj
Returns
void

Set input values to a object from this action form. This member function mediates between logic and the result of validations. For example, developers can use this method to set values to XoopsSimpleObject.

This member function is abstract. But, the subclass of this class does not have to implement it.

◆ validate()

validate ( )

Validates fetched values.

Returns
void

Performs validation, so that if an input value is wrong, error messages are added to the error message buffer. The validation procedure is as follows:

  • 1. If this object has a token name, validate the unique one-time token.
  • 2. Call the member function to validate all the properties of the field.
  • 3. Call the member function that is defined in the subclass.

For a database, validations are performed by functions of the properties of each field. But, the subclass can define its own validation logic. Define member function with name "validate" + "form name". For example, to validate "message", define the function "validateMessage()".

Field Documentation

◆ $_mToken

$_mToken

string

Token string as one-time token.

◆ $mContext

$mContext

[READ ONLY] XCube_HttpContext

The context object. Allows to access the HTTP-request information. Basically, this member property is read only. Initialized in the constructor.

◆ $mErrorFlag

$mErrorFlag = false

bool

Attention
This is temporary until we decide on the method of error handling.

◆ $mUser

$mUser

[READ ONLY] XCube_Principal

The object implementing the interface of XCube_Principal. Allows you to check the permissions of the current HTTP-request through principal object. Basically, this member property is read only. Initialized in constructor.


The documentation for this class was generated from the following file: