1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-26 03:30:48 +03:00

Доработка ajax валидации полей

This commit is contained in:
Denis Shakhov 2015-11-27 23:22:38 +07:00
parent 450ab1161c
commit 5b93a0fad1
4 changed files with 36 additions and 10 deletions

View file

@ -469,17 +469,19 @@ class ActionAjax extends Action
/**
* Ajax валидация каптчи
*
* @apiParam {String} name Уникальное название каптчи
* @apiParam {String} captcha Значение каптчи для проверки
*/
protected function EventCaptchaValidate()
{
$sName = isset($_REQUEST['params']['name']) ? $_REQUEST['params']['name'] : '';
$sValue = isset($_REQUEST['fields'][0]['value']) ? $_REQUEST['fields'][0]['value'] : '';
$sField = isset($_REQUEST['fields'][0]['field']) ? $_REQUEST['fields'][0]['field'] : '';
$sName = isset($_REQUEST['name']) ? $_REQUEST['name'] : '';
$sValue = isset($_REQUEST['captcha']) ? $_REQUEST['captcha'] : '';
$sCaptchaValidateType = func_camelize('captcha_' . Config::Get('sys.captcha.type'));
if (!$this->Validate_Validate($sCaptchaValidateType, $sValue, array('name' => $sName))) {
$aErrors = $this->Validate_GetErrors();
$this->Viewer_AssignAjax('aErrors', array(htmlspecialchars($sField) => array(reset($aErrors))));
$this->Viewer_AssignAjax('aErrors', array('captcha' => array(reset($aErrors))));
}
}
@ -789,6 +791,7 @@ class ActionAjax extends Action
));
$aPaging = $this->Viewer_MakePaging($aResult['count'], $iPage, 20, Config::Get('pagination.pages.count'), null);
$aMediaItems = $aResult['collection'];
$this->Viewer_AssignAjax('pagination', $aPaging);
}
$oViewer = $this->Viewer_GetLocalViewer();
@ -797,7 +800,6 @@ class ActionAjax extends Action
$oViewer->Assign('oMediaItem', $oMediaItem);
$sTemplate .= $oViewer->Fetch('component@uploader.file');
}
$this->Viewer_AssignAjax('html', $sTemplate);
$this->Viewer_AssignAjax('count_loaded', count($aMediaItems));
$this->Viewer_AssignAjax('page', count($aMediaItems) > 0 ? $iPage + 1 : $iPage);

View file

@ -70,6 +70,8 @@ class ActionAuth extends Action
$this->AddEvent('ajax-login', 'EventAjaxLogin');
$this->AddEvent('ajax-password-reset', 'EventAjaxPasswordReset');
$this->AddEvent('ajax-validate-fields', 'EventAjaxValidateFields');
$this->AddEvent('ajax-validate-login', 'EventAjaxValidateLogin');
$this->AddEvent('ajax-validate-email', 'EventAjaxValidateEmail');
$this->AddEvent('ajax-register', 'EventAjaxRegister');
$this->AddEvent('ajax-reactivation', 'EventAjaxReactivation');
}
@ -251,11 +253,34 @@ class ActionAuth extends Action
}
}
/**
* Ajax валидация форму регистрации
*/
protected function EventAjaxValidateFields()
{
$this->ValidateFields(getRequest('fields'));
}
/**
* Ajax валидация логина
*/
protected function EventAjaxValidateLogin()
{
$this->ValidateFields(array(array('field' => 'login', 'value' => getRequest('login'))));
}
/**
* Ajax валидация емэйла
*/
protected function EventAjaxValidateEmail()
{
$this->ValidateFields(array(array('field' => 'email', 'value' => getRequest('email'))));
}
/**
* Ajax валидация форму регистрации
*/
protected function ValidateFields($aFields)
{
/**
* Устанавливаем формат Ajax ответа
@ -269,7 +294,6 @@ class ActionAuth extends Action
/**
* Пробегаем по переданным полям/значениям и валидируем их каждое в отдельности
*/
$aFields = getRequest('fields');
if (is_array($aFields)) {
foreach ($aFields as $aField) {
if (isset($aField['field']) and isset($aField['value'])) {

View file

@ -14,11 +14,11 @@
{* Логин *}
{component 'field' template='text'
name = 'login'
rules = [ 'required' => true, 'minlength' => '3', 'remote' => "{router page='auth'}ajax-validate-fields" ]
rules = [ 'required' => true, 'minlength' => '3', 'remote' => "{router page='auth'}ajax-validate-login" ]
label = $aLang.auth.labels.login}
{* E-mail *}
{component 'field' template='email' rules=[ 'remote' => "{router page='auth'}ajax-validate-fields" ]}
{component 'field' template='email' rules=[ 'remote' => "{router page='auth'}ajax-validate-email" ]}
{* Пароль *}
{component 'field' template='text'

@ -1 +1 @@
Subproject commit 09ee27d08208a2cb80ac95b70db1115178e17d73
Subproject commit a6f66117f5e8ca71197eef29cc9949c5e5c27164