Код который посылает запрос к контроллеру и получает ответ
<script>
(function($) {
$(document).ready(function(){
if( $('#wpforms-form-446').length ) {
$('#wpforms-submit-446').prop('disabled', true);
$('#wpforms-446-field_21, #wpforms-446-field_3').change(function(){
check();
});
$('#wpforms-form-446 .wpforms-field-container').append('<div id="errs"></div>');
$('#wpforms-submit-446').click(function(event){
if( $('#wpforms-submit-446').prop('disabled') )
return;
let email = $('#wpforms-446-field_3').val();
let phone = $('#wpforms-446-field_21').val();
let password = $('#wpforms-446-field_4').val();
let name = $('#wpforms-446-field_1').val();
if( email.length == 0 || phone.length == 0 )
return;
$.ajax({
method: "POST",
dataType : 'json',
url: "/api.php?create-user",
data: { email: email, phone: phone, password: password, name: name }
})
.success(function( msg ) {
$('#errs').html('');
console.log(msg)
});
});
function check() {
let email = $('#wpforms-446-field_3').val();
let phone = $('#wpforms-446-field_21').val();
if( email.length == 0 || phone.length == 0 )
return;
$.ajax({
method: "POST",
dataType : 'json',
url: "/api.php?has-user",
data: { email: email, phone: phone }
})
.success(function( msg ) {
$('#errs').html('');
let b_error = false;
if( msg.error !== undefined ) {
let error = msg.error;
for (var variable in error) {
b_error = true;
$('#errs').append('<label class="wpforms-error">'+error[variable]+'</label>');
}
}
else {
if( msg.result !== undefined && msg.result == true ) {
b_error = true;
$('#errs').append('<label class="wpforms-error">Пользователь существует. <a href="https://a-n-h.space/rm_login/">Войти</a></label>');
}
}
if( b_error == false ) {
$('#wpforms-submit-446').prop('disabled', false);
}
});
}
}
});
})( jQuery );
</script>