POST-requests processing

All data from the form, and the data sent by Ajax-requests processed class Module_name_action, described in the file modules/module_name/module_name.action.php.

Processing connected whenever passed variable $_POST["module"] = 'module_name';.

Access to this file is via controller modules/module_name/module_name.php. If the controller described function action(), it determines what function in the file modules/module_name/module_name.action.php whichever is conveyed in the variable $_POST["action"]. If the function action() is not described in the controller, the function init() is called in the file modules/module_name/module_name.action.php.

The data module may be transmitted even if it is not connected to any page. Compliance Test attached to the module and the resulting module page performed during query processing, if necessary.

Class structure can be of any order to implement the functionality provided.

Class Action

Class Module_name_action inherits class Action described in the file includes/action.php.

Methods

Свойства

var result – полученный после обработки данных результат.

Методы

void end () – Отправляет ответ.

The function is called from includes/init.php after any call to action processing module.

Example:

$module = new Feedback_action($this->diafan);
$module->action();
$module->action->end();

boolean result () – Проверяет сформирован ли ответ.

Example:

if(empty($_POST["mail"]))
{
    
$this->result["errors"]["mail"] = "Введите e-mail.";
}

// if the answer is prepared (for example, an error is found in transmitted data),
// stop the execution of the processing function
if ($this->result())
    return;

void check_user () – Проверяет авторизован ли пользователь на сайте.

Example:

// check whether the user is authorized
$this->check_user();

// if an error is found, stop the execution of the processing function
if ($this->result())
    return;

void check_user_hash () – Проверяет хэш пользователя.

Example:

// check whether the correct user hash
$this->check_user_hash();

// if an error is found, stop the execution of the processing function
if ($this->result())
    return;

void empty_required_field (array $config) – Проверяет на заполнение обязательных полей.

  • array $config: настройки функции: params поля формы, prefix префикс

If the specified field in the form requiring mandatory filling, the correct input can be tested with this function. List of fields requiring validation must be passed as an argument.

Example:

// get fields of feedback form
$params = $this->model->get_params(array("module" => "feedback", "where" => "site_id=".$site_id));

// check whether the required fields are filled
$this->empty_required_field(array("params" => $params));

// if an error is found, stop the execution of the processing function
if ($this->result())
    return;

void insert_values (array $config) – Добавляет значение полей формы в базу данных.

  • array $config: настройки функции: id номер элемента, table таблица, params поля формы, multilang значения переводятся

This function gets a list of arguments, according to which records the values into the database. Called when processing data from the form.

Example:

// modules/cart/cart.action.php
// write data during the ordering process in the module "Cart"
$this->insert_values(array("id" => $order_id, "table" => "shop_order", "params" => $params));

boolean check_site_id () – Проверяет корректность номера страницы сайта..

Example:

// check whether correct site page ID,
// to which the module is connected
$this->check_site_id();

// if an error is found, stop the execution of the processing function
if ($this->result())
    return;

void check_captcha () – Проверяет правильность капчи.

When you call a function that accesses to class "Captcha" Methods to validate input. If captcha is incorrect, a message will be returned with an error.

Example:

// check whether the code is entered correctly
$this->check_site_id();

// if an error is found, stop the execution of the processing function
if ($this->result())
    return;

void update_values (array $config) – Обновляет значение полей формы в базу данных.

  • array $config: настройки функции: id номер элемента, table таблица, params поля формы, prefix префикс, multilang значения переводятся

Example:

// modules/usersettings/usersettings.action.php
// change the current use data when editing a profile via personal cabinet
$this->update_values(array("id" => $this->diafan->_users->id, "table" => "users", "params" => $params));

boolean valid_email (string $email, string $field) – Проверка e-mail на валидность.

  • string $email: e-mail
  • string $field: название поля в массиве $_POST

Use a third-party file includes/validate.php. When fail verification will be returned TRUE, and added a message to the wrong e-mail address format.

Example:

// modules/faq/faq.action.php
// validation format e-mail address entered when sending the question; module "Question-Answer"
$this->valid_email($_POST['email'], "email");

// if an error is found, stop the execution of the processing function
if ($this->result())
    return;

boolean valid_phone (string $phone, string $field) – Проверка телефона на валидность.

  • string $phone: phone
  • string $field: название поля в массиве $_POST

Example:

// modules/registration/registration.action.php
// validation format introduced the phone when the user register
$this->valid_phone($_POST['phone'], "phone");

// if an error is found, stop the execution of the processing function
if ($this->result())
    return;

boolean valid_url (string $url, string $field) – Проверка ссылки на валидность.

  • string $url: link
  • string $field: название поля в массиве $_POST

void action () – Обрабатывает полученные данные из формы.