<?php
require_once __DIR__ . '/mailer/Validator.php';
require_once __DIR__ . '/mailer/ContactMailer.php';
if (!Validator::isAjax() || !Validator::isPost()) {
echo 'Доступ запрещен!';
exit;
}
$name = isset($_POST['name']) ? trim(strip_tags($_POST['name'])) : null;
$email = isset($_POST['email']) ? trim(strip_tags($_POST['email'])) : null;
$phone = isset($_POST['phone']) ? trim(strip_tags($_POST['phone'])) : null;
$message = isset($_POST['message']) ? trim(strip_tags($_POST['message'])) : null;
if (empty($name) || empty($email) || empty($phone) || empty($message)) {
echo 'Все поля обязательны для заполнения.';
exit;
}
if (!Validator::isValidEmail($email)) {
echo 'E-mail не соответствует формату.';
exit;
}
if (!Validator::isValidPhone($phone)) {
echo 'Телефон не соответствует формату.';
exit;
}
if (ContactMailer::send($name, $email, $phone, $message)) {
echo htmlspecialchars($name) . ', ваше сообщение успешно отправлено.';
} else {
echo htmlspecialchars($name) . ', ваше сообщение успешно отправлено.';
}
exit;
<form action="handler.php" id="contactForm" method="post">
<input class="field" id="name" name="name" placeholder="firstname" required type="text">
<br>
<input class="field" id="email" name="email" placeholder="lastname" required type="text">
<br>
<input class="field" id="phone" name="phone" placeholder="Phone" required type="text">
<br>
<textarea class="field" id="message" name="message" placeholder="Write your message here..."
type="text"></textarea>
<br><br>
<button id="button" name="btn_submit" type="submit" value="SEND">SEND</button>
<div class="result">
<span id="answer"></span>
<span id="loader"><img alt="" src="img/loader.gif"></span>
</div>
</form>
// Отправляет данные из формы на сервер и получает ответ
$('#contactForm').on('submit', function(event) {
event.preventDefault();
var form = $('#contactForm'),
button = $('#button'),
answer = $('#answer'),
loader = $('#loader');
$.ajax({
url: 'handler.php',
type: 'POST',
data: form.serialize(),
beforeSend: function() {
answer.empty();
button.attr('disabled', true).css('margin-bottom', '20px');
loader.fadeIn();
},
success: function(result) {
loader.fadeOut(300, function() {
answer.text(result);
});
form.find('.field').val('');
button.attr('disabled', false);
},
error: function() {
loader.fadeOut(300, function() {
answer.text('Произошла ошибка! Попробуйте позже.');
});
button.attr('disabled', false);
}
});
});
<form action="handler.php" id="contactForm" method="post">
<input class="field" id="name" name="name" placeholder="firstname" required type="text">
<br>
<input class="field" id="email" name="email" placeholder="lastname" required type="text">
<br>
<input class="field" id="phone" name="phone" placeholder="Phone" required type="text">
<br>
<textarea class="field" id="message" name="message" placeholder="Write your message here..."
type="text"></textarea>
<br><br>
<button id="button" name="btn_submit" type="submit" value="SEND">SEND</button>
<div class="result">
<span id="answer"></span>
<span id="loader"><img alt="" src="img/loader.gif"></span>
</div>
</form>
// Отправляет данные из формы на сервер и получает ответ
$('#contactForm').on('submit', function(event) {
event.preventDefault();
var form = $('#contactForm'),
button = $('#button'),
answer = $('#answer'),
loader = $('#loader');
$.ajax({
url: 'handler.php',
type: 'POST',
data: form.serialize(),
beforeSend: function() {
answer.empty();
button.attr('disabled', true).css('margin-bottom', '20px');
loader.fadeIn();
},
success: function(result) {
loader.fadeOut(300, function() {
answer.text(result);
});
form.find('.field').val('');
button.attr('disabled', false);
},
error: function() {
loader.fadeOut(300, function() {
answer.text('Произошла ошибка! Попробуйте позже.');
});
button.attr('disabled', false);
}
});
});
ERROR - FUNCTION - callback; MESSAGE - !empty($_POST);
INFO - () () FUNCTION - checkout_form; MESSAGE - initialization checkout_form;
INFO - () () FUNCTION - checkout_form; MESSAGE - getting string info; info - Оплата заказа номер 376 в интернет-магазине https://avtogalant.by;
INFO - () () FUNCTION - checkout_form; MESSAGE - getting a action; action - https://avtogalant.by/payment/ExpressPayCard/callb...
INFO - () () FUNCTION - checkout_form; MESSAGE - getting a button; button - ;
INFO - () () FUNCTION - callback; MESSAGE - start processing data from the server;
INFO - () () FUNCTION - callback; MESSAGE - REQUEST - https://api.express-pay.by/v1/cardinvoices?token=d... заказа номер 376 в интернет-магазине https://avtogalant.by,https://avtogalant.by/paymen... к оплате,1551279574527263764,1551279574,GA1.2.1621146110.1551279574,fb.1.1551279574370.1005853672,duZHzEKOj2bgIBpE3LDU87xv,i7qn9qqne2nhe09pdnvilmp7e1,GA1.2.869232585.1562650554,2,kg16bvs8cj2d6ju4sncpajj8j7,w,500398,500323,500318,500317,500219,500198,500194,500193,499478,499403,499394,499366,499365,499361,499350,499333,499336,499131,499077,499076,499068,499061,499050,499025,498993,498876,498869,498868,498802,498734,498704,498697,498688,494172,494170,480468,492914,497716,498652,498589,501638,501365,493589,501681,501680,493536,496855,501774,501765,501778,501767,501770,501783,501801,501735,501725,498593,498854,500489,500531,501813,501717,501691,476492,500472,500418,500409,500403,500407,500402,500955,500466,501352,501347,501171,500737,501806,501918,500442,501262,501897,501808,501909,501807,495251,499477,499448,499421,499439,499362,499138,501880,501827,501800,500876,493994,492053,501291,501285,501809,1;
INFO - () () FUNCTION - callback; MESSAGE - $_SERVER["REQUEST_METHOD"] === "POST";
INFO - () () FUNCTION - callbackPost; MESSAGE - retrieving data from a POST request; url - https://api.express-pay.by/v1/cardinvoices?token=d... accountNo - 376; expiration - ; amount - 542,40; currency - 933; info - Оплата заказа номер 376 в интернет-магазине https://avtogalant.by; return_url - https://avtogalant.by/payment/ExpressPayCard/callb... fail_url - https://avtogalant.by/payment/ExpressPayCard/callb... language - ; sessionTimeoutSecs - 700; expirationdate - ;
INFO - () () FUNCTION - addInvoice; MESSAGE - converting data amount: amount - 542,40;
INFO - () () FUNCTION - addInvoice; MESSAGE - converting data from json to an array : requestParams - 376 , , 542,40 , 933 , Оплата заказа номер 376 в интернет-магазине https://avtogalant.by , https://avtogalant.by/payment/ExpressPayCard/callb... , https://avtogalant.by/payment/ExpressPayCard/callb... , , 700 , ;
INFO - () () FUNCTION - callbackPost; MESSAGE - Received response from the server; response - {"CardInvoiceNo":40714};
INFO - () () FUNCTION - callbackPost; MESSAGE - converting data from json to array : RESPONSE - 40714;
INFO - () () FUNCTION - callbackPost; MESSAGE - getting url - https://api.express-pay.by/v1/cardinvoices/40714/p...
INFO - () () FUNCTION - callbackPost; MESSAGE - Get response; RESPONSE - {"FormUrl":"https://mpi.bgpb.by/payment/merchants/default/paym..."};
INFO - () () FUNCTION - success; MESSAGE - starting success function;
INFO - () () FUNCTION - success; MESSAGE - display result;
INFO - () () FUNCTION - callback; MESSAGE - start processing data from the server;
INFO - () () FUNCTION - callback; MESSAGE - REQUEST - fail,376,1551279574527263764,1551279574,GA1.2.1621146110.1551279574,fb.1.1551279574370.1005853672,duZHzEKOj2bgIBpE3LDU87xv,i7qn9qqne2nhe09pdnvilmp7e1,GA1.2.869232585.1562650554,2,kg16bvs8cj2d6ju4sncpajj8j7,w,500398,500323,500318,500317,500219,500198,500194,500193,499478,499403,499394,499366,499365,499361,499350,499333,499336,499131,499077,499076,499068,499061,499050,499025,498993,498876,498869,498868,498802,498734,498704,498697,498688,494172,494170,480468,492914,497716,498652,498589,501638,501365,493589,501681,501680,493536,496855,501774,501765,501778,501767,501770,501783,501801,501735,501725,498593,498854,500489,500531,501813,501717,501691,476492,500472,500418,500409,500403,500407,500402,500955,500466,501352,501347,501171,500737,501806,501918,500442,501262,501897,501808,501909,501807,495251,499477,499448,499421,499439,499362,499138,501880,501827,501800,500876,493994,492053,501291,501285,501809;
ERROR - () () FUNCTION - callback; MESSAGE - $_SERVER["REQUEST_METHOD"] !== "POST";
INFO - () () FUNCTION - fail; MESSAGE - starting fail function;
INFO - () () FUNCTION - fail; MESSAGE - display result;
ERROR - () () FUNCTION - callback; MESSAGE - $_SERVER["REQUEST_METHOD"] !== "POST";
Ну а если 2, то на оборот