#46734 Kopusha:
1. в users/inc/ создаем users.ajax.php
<?php
defined('COT_CODE') or die('Wrong URL');
global $db_users, $db;
include_once cot_incfile("users", "module");
$a = cot_import('a', 'G', 'TXT');
$m = cot_import("m", "G", "TXT");
$login = cot_import("login", "G", "TXT");
$email = cot_import("email", "G", "TXT");
$data["success"] = false;
if ($a == "checklogin") {
$user_exists = (bool)cot::$db->query("SELECT user_id FROM ".cot::$db->users." WHERE user_name = ? LIMIT 1",
array($login))->fetch();
$data["text"] = //как отработать оповещение, у каждого свое
$data["user_exists"] = $user_exists;
print json_encode($data);
}
if ($a == "checkemail") {
$email_exists = (bool)cot::$db->query("SELECT user_id FROM ".cot::$db->users." WHERE user_email = ? LIMIT 1",
array($email))->fetch();
$data["text"] = //как отработать оповещение, у каждого свое
$data["email_exists"] = $email_exists;
print json_encode($data);
}
в корне users - users.rc.php
<?php
/* ====================
[BEGIN_COT_EXT]
Hooks=rc
Order=9999
[END_COT_EXT]
==================== */
defined('COT_CODE') or die('Wrong URL');
if ($usr['id'] > 0) {
}
else
{
if ($_GET['e'] == 'users' && $_GET['m'] == 'register') {
cot_rc_link_footer("modules/users/js/users.js");
}
}
Далее users/js/users.js
$(function () {
$('#form input:text[name="rusername"]').blur(function() {
if($(this).val().length>=2)
{
$login = $(this).val();
$.ajax({
url: 'index.php?e=users&m=ajax&a=checklogin&login=' + $login,
method: "GET",
}).done(function (h) {
d = $.parseJSON(h);
if (d.user_exists) {
//тут как фронэнд отработает код ошибки
}
});
return false;
}
});
$('#useremail').blur(function() {
if($(this).val().length>=2)
{
$email = $(this).val();
$.ajax({
url: 'index.php?e=users&m=ajax&a=checkemail&email=' + $email,
method: "GET",
}).done(function (h) {
d = $.parseJSON(h);
if (d.email_exists) {
//тут как фронэнд отработает код ошибки
$('.email input').parent().removeClass('success');
}
else
{
//email validation
var regex = new RegExp(
'^(([^<>()[\\]\\\\.,;:\\s@\\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\\"]+)*)|' +
'(\\".+\\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])' +
'|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$'
);
$('.email input').on('keyup', function(e) {
$(this).parent().toggleClass('success', regex.test($(this).val()));
});
}
});
return false;
}
});
});
вроде бы все, выдирал с рабочего проекта где много другого, может что и забыл
модуль есесно обновить
Кстати это решение если оформить в виде плагина то будет действительно проще и лаконичнее для понимания + лучше илюстрирует работу движковых систем