1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-28 20:45:00 +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 валидация каптчи * Ajax валидация каптчи
*
* @apiParam {String} name Уникальное название каптчи
* @apiParam {String} captcha Значение каптчи для проверки
*/ */
protected function EventCaptchaValidate() protected function EventCaptchaValidate()
{ {
$sName = isset($_REQUEST['params']['name']) ? $_REQUEST['params']['name'] : ''; $sName = isset($_REQUEST['name']) ? $_REQUEST['name'] : '';
$sValue = isset($_REQUEST['fields'][0]['value']) ? $_REQUEST['fields'][0]['value'] : ''; $sValue = isset($_REQUEST['captcha']) ? $_REQUEST['captcha'] : '';
$sField = isset($_REQUEST['fields'][0]['field']) ? $_REQUEST['fields'][0]['field'] : '';
$sCaptchaValidateType = func_camelize('captcha_' . Config::Get('sys.captcha.type')); $sCaptchaValidateType = func_camelize('captcha_' . Config::Get('sys.captcha.type'));
if (!$this->Validate_Validate($sCaptchaValidateType, $sValue, array('name' => $sName))) { if (!$this->Validate_Validate($sCaptchaValidateType, $sValue, array('name' => $sName))) {
$aErrors = $this->Validate_GetErrors(); $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); $aPaging = $this->Viewer_MakePaging($aResult['count'], $iPage, 20, Config::Get('pagination.pages.count'), null);
$aMediaItems = $aResult['collection']; $aMediaItems = $aResult['collection'];
$this->Viewer_AssignAjax('pagination', $aPaging);
} }
$oViewer = $this->Viewer_GetLocalViewer(); $oViewer = $this->Viewer_GetLocalViewer();
@ -797,7 +800,6 @@ class ActionAjax extends Action
$oViewer->Assign('oMediaItem', $oMediaItem); $oViewer->Assign('oMediaItem', $oMediaItem);
$sTemplate .= $oViewer->Fetch('component@uploader.file'); $sTemplate .= $oViewer->Fetch('component@uploader.file');
} }
$this->Viewer_AssignAjax('html', $sTemplate); $this->Viewer_AssignAjax('html', $sTemplate);
$this->Viewer_AssignAjax('count_loaded', count($aMediaItems)); $this->Viewer_AssignAjax('count_loaded', count($aMediaItems));
$this->Viewer_AssignAjax('page', count($aMediaItems) > 0 ? $iPage + 1 : $iPage); $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-login', 'EventAjaxLogin');
$this->AddEvent('ajax-password-reset', 'EventAjaxPasswordReset'); $this->AddEvent('ajax-password-reset', 'EventAjaxPasswordReset');
$this->AddEvent('ajax-validate-fields', 'EventAjaxValidateFields'); $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-register', 'EventAjaxRegister');
$this->AddEvent('ajax-reactivation', 'EventAjaxReactivation'); $this->AddEvent('ajax-reactivation', 'EventAjaxReactivation');
} }
@ -251,11 +253,34 @@ class ActionAuth extends Action
} }
} }
/** /**
* Ajax валидация форму регистрации * Ajax валидация форму регистрации
*/ */
protected function EventAjaxValidateFields() 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 ответа * Устанавливаем формат Ajax ответа
@ -269,7 +294,6 @@ class ActionAuth extends Action
/** /**
* Пробегаем по переданным полям/значениям и валидируем их каждое в отдельности * Пробегаем по переданным полям/значениям и валидируем их каждое в отдельности
*/ */
$aFields = getRequest('fields');
if (is_array($aFields)) { if (is_array($aFields)) {
foreach ($aFields as $aField) { foreach ($aFields as $aField) {
if (isset($aField['field']) and isset($aField['value'])) { if (isset($aField['field']) and isset($aField['value'])) {

View file

@ -14,11 +14,11 @@
{* Логин *} {* Логин *}
{component 'field' template='text' {component 'field' template='text'
name = 'login' 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} label = $aLang.auth.labels.login}
{* E-mail *} {* 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' {component 'field' template='text'

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