Я впервые спрашиваю здесь, надеюсь, я смогу найти решение по моей проблеме. (Примечание: я не очень хорошо разбираюсь в ajax, но я могу понять столько, сколько могу ... просто больше исследований.
ниже моя проблема: мое письмо успешно отправлено, и я получил письмо, но я состояние кнопки и формы не изменилось .. заголовок кнопки отправки не вернулся к нормальному состоянию, как и в случае с enter code here
ll, просто нет ... просто говорит ... Отправка ... (заголовок кнопки после отправки формы К вашему сведению: я просто изменил этот код из другого источника, чтобы он работал в моей форме ... я добавляю капчу, которая не включена в коды электронной почты. Ниже приведены полные коды.
| форма html
| php почтовый код:
<?php session_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$mail_to = "myemail@domain.com";
# Sender Data `enter code here`
$subject = trim($_POST["subject"]);
$name = str_replace(array("\r", "\n"), array(" ", " "), strip_tags(trim($_POST["name"])));
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$phone = trim($_POST["phone"]);
$message = trim($_POST["message"]);
$captcha = trim($_POST["captcha"]);
if (empty($name) or !filter_var($email, FILTER_VALIDATE_EMAIL) or empty($phone) or empty($subject) or empty($message)) {
# Set a 400 (bad request) response code and exit.
http_response_code(400);
echo "Please complete the form and try again.";
exit;
}
if (empty($_SESSION['captcha']) || trim(strtolower($captcha)) != $_SESSION['captcha']) {
unset($_SESSION['captcha']);
//$hasError = true;
// http_response_code(400);
echo "Captcha code not match try again.";
exit;
} else {
$captcha = trim($_POST['captcha']);
exit;
}
# Mail Content
$content = "Name: $name\n";
$content .= "Email: $email\n\n";
$content .= "Phone: $phone\n";
$content .= "Message:\n$message\n";
# email headers.
$headers = "From: $name <$email>";
# Send the email.
$success = mail($mail_to, $subject, $content, $headers);
if ($success) {
# Set a 200 (okay) response code.
http_response_code(200);
echo "Thank You! Your message has been sent.";
} else {
# Set a 500 (internal server error) response code.
http_response_code(500);
echo "Oops! Something went wrong, we couldn't send your message.";
}
} else {
# Not a POST request, set a 403 (forbidden) response code.
http_response_code(403);
echo "There was a problem with your submission, please try again.";
}
| the js код:
$(function () {
function after_form_submitted(data) {
if (data.result == 'success') {
$('form#reused_form').hide();
$('#success_message').show();
$('#error_message').hide();
}
else {
$('#error_message').append('<ul></ul>');
jQuery.each(data.errors, function (key, val) {
$('#error_message ul').append('<li>' + key + ':' + val + '</li>');
});
$('#success_message').hide();
$('#error_message').show();
//reverse the response on the button
$('button[type="button"]', $form).each(function () {
$btn = $(this);
label = $btn.prop('orig_label');
if (label) {
$btn.prop('type', 'submit');
$btn.text(label);
$btn.prop('orig_label', '');
}
});
}//else
}
$('#reused_form').submit(function (e) {
e.preventDefault();
$form = $(this);
//show some response on the button
$('button[type="submit"]', $form).each(function () {
$btn.prop('type', 'button');
$btn.prop('orig_label', $btn.text());
$btn.text('Sending ...');
});
$.ajax({
type: "POST",
url: 'mail.php',
data: $form.serialize(),
success: after_form_submitted,
dataType: 'json'
});
});
});
я надеюсь, что вы можете помочь мне исправить код .. так как я не эксперт .. но хочу учиться
Заранее спасибо