FormHandler Class Reference
[Controller]
Wraps functionality related to forms. More...
Public Member Functions |
|
__construct ($name, $path= '', $token_policy=self::TOKEN_POLICY_UNIQUE) | |
Constructor. |
|
error ($status) | |
Called if form has finished unsucessfully.
|
|
finish ($status, $success_message= '') | |
Called after a form has been processed.
|
|
fix_post_history ($status=null) | |
Allows back button in browser even after
POST. |
|
prepare_view ($view, $data=false) | |
Set data required on view. |
|
success ($message) | |
Called if a form has been processed
successfully. |
|
validate ($data=false) | |
Validate a Form. |
|
Public Attributes |
|
const | TOKEN_POLICY_NONE = 0 |
Do not use tokens. |
|
const | TOKEN_POLICY_REUSE = 2 |
Create a token for a form, but reuse it
throughout the request (used for commands forms). |
|
const | TOKEN_POLICY_REUSE_ACROSS_REQUESTS = 3 |
Create a token for a form, and reuse it for
several requests (until it expires). |
|
const | TOKEN_POLICY_UNIQUE = 1 |
Create a token on each request. |
Detailed Description
Wraps functionality related to forms.
Definition at line 10 of file formhandler.cls.php.
Constructor & Destructor Documentation
FormHandler::__construct | ( | $ | name, | |
$ | path = '' , |
|||
$ | token_policy =
self::TOKEN_POLICY_UNIQUE |
|||
) |
Constructor.
- Parameters:
-
string $name Name of form string $path (optional) Path of form , if != current path bool $create_token True to create a unique token to identify Form
Definition at line 53 of file formhandler.cls.php.
00053 { 00054 // Compatability 00055 if ($token_policy === false) { 00056 $token_policy = self::TOKEN_POLICY_NONE; 00057 } 00058 else if ($token_policy === true) { 00059 $token_policy = self::TOKEN_POLICY_UNIQUE; 00060 } 00061 00062 $this->name = $name; 00063 $this->token_policy = $token_policy; 00064 $this->url = Url::current(); 00065 if (!empty($path)) { 00066 $this->url->set_path($path); 00067 } 00068 }
Member Function Documentation
FormHandler::error | ( | $ | status | ) |
Called if form has finished unsucessfully.
- Parameters:
-
Status|string $status
Definition at line 197 of file formhandler.cls.php.
FormHandler::finish | ( | $ | status, | |
$ | success_message =
'' |
|||
) |
Called after a form has been processed.
- Parameters:
-
Status $status string $success_message Optional message to display on success
Definition at line 166 of file formhandler.cls.php.
00166 { 00167 $params = array( 00168 'name' => $this->name, 00169 'status' => $status 00170 ); 00171 EventSource::Instance()->invoke_event_no_result('form_finished', $params); 00172 00173 if ($status->is_error()) { 00174 $this->error($status); 00175 } 00176 else { 00177 $msg = ($status->is_empty()) ? $success_message : $status->to_string(Status::OUTPUT_PLAIN); 00178 $this->success($msg); 00179 } 00180 }
FormHandler::fix_post_history | ( | $ | status = null |
) |
Allows back button in browser even after POST.
Does a redirect. Requires open session. Stores POST data (restored in constructor)
- Parameters:
-
Status $status
Definition at line 213 of file formhandler.cls.php.
FormHandler::prepare_view | ( | $ | view, | |
$ | data = false |
|||
) |
Set data required on view.
- Parameters:
-
View The view to populate with data mixed Array or Object containing key/value-pairs for default data
Definition at line 76 of file formhandler.cls.php.
00076 { 00077 $token = $this->create_token(); 00078 00079 $token_html = ''; 00080 if ($token) { 00081 $token_html .= html::input('hidden', Config::get_value(Config::FORMVALIDATION_FIELD_NAME), array('value' => $token)); 00082 $token_html .= html::input('hidden', Config::get_value(Config::FORMVALIDATION_HANDLER_NAME), array('value' => $this->name)); 00083 00084 } 00085 $view->assign('form_validation', $token_html); 00086 00087 if (!empty($data)) { 00088 $this->set_form_data_on_view((array)$data,$view); 00089 } 00090 00091 $form_data = $this->restore_post_data(); 00092 $this->set_form_data_on_view($form_data, $view); 00093 }
FormHandler::success | ( | $ | message | ) |
Called if a form has been processed successfully.
- Parameters:
-
Status|string $message
Definition at line 187 of file formhandler.cls.php.
00187 { 00188 History::go_to(0, $message); 00189 exit; 00190 }
FormHandler::validate | ( | $ | data = false |
) |
Validate a Form.
- Returns:
- Status
Definition at line 142 of file formhandler.cls.php.
00142 { 00143 if ($data === false) { 00144 $data = $_POST; 00145 } 00146 $ret = new Status(); 00147 $success = true; 00148 if ($this->token_policy != self::TOKEN_POLICY_NONE) { 00149 $token = Arr::get_item($data, Config::get_value(Config::FORMVALIDATION_FIELD_NAME), ''); 00150 // Validate if token is in DB 00151 $success = $success && ($this->name == Arr::get_item($data, Config::get_value(Config::FORMVALIDATION_HANDLER_NAME), '')); 00152 $success = $success && FormValidations::validate_token($this->name, $token); 00153 } 00154 if ($success == false) { 00155 $ret->append(tr('Form verification token is too old. Please try again.', 'core')); 00156 } 00157 return $ret; 00158 }
Member Data Documentation
const FormHandler::TOKEN_POLICY_NONE = 0 |
Do not use tokens.
Definition at line 18 of file formhandler.cls.php.
const FormHandler::TOKEN_POLICY_REUSE = 2 |
Create a token for a form, but reuse it throughout the request (used for commands forms).
Definition at line 22 of file formhandler.cls.php.
Create a token for a form, and reuse it for several requests (until it expires).
- Attention:
- Note this may lead to behaviours that users may find strange: tokens expiring after short time, invalidating of forms, if more than one browser window is opened etc.
Definition at line 29 of file formhandler.cls.php.
const FormHandler::TOKEN_POLICY_UNIQUE = 1 |
Create a token on each request.
Definition at line 14 of file formhandler.cls.php.
The documentation for this class was generated from the following file:
- gyro/core/controller/tools/formhandler.cls.php