gpt4 book ai didi

javascript - 联系表格在 iPhone 上无效

转载 作者:行者123 更新时间:2023-12-02 17:48:48 26 4
gpt4 key购买 nike

从 iPhone 提交时,以下联系表单无效...可以在这里预览:loaistudio.com/contact

当我尝试在不删除字段的情况下提交表单时,它打开了一个新的空白页,仅在左上角显示数字 1“这根本不应该做”,并且实际上将表单发送为空......它在桌面上不会这样做。

我尝试了代码试图找到问题,但不知道问题出在哪里!请帮忙。

   <?php
session_start();

if ($_SERVER['REQUEST_METHOD'] == 'POST'){
ob_start();

if(isset($_POST['name'])
&& isset($_POST['email'])
&& isset($_POST['message'])
&& isset($_POST['token'])){

if($_SESSION['token'] != $_POST['token']){
$response = "0";
} else {
$_SESSION['token'] = "";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$to = "EMAIL GOES HERE";
$subject = "New Message From: $name";
$message = "$message";

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: '.$email . "\r\n";
$mailed = ( mail($to, $subject, $message, $headers) );

if( isset($_POST['ajax']))$response = ($mailed) ? "1" :
"0"; else $response = ($mailed) ? "<h2>Success!</h2>" :
"<h2>Error! There was a problem with sending.</h2>";
echo $response;
}

} else {
echo "Form data error!";
}

ob_flush();
die();
}

?>
<!DOCTYPE html>
<html class="no-js">
<head>
<title>Contact us | Website</title>
</head>

<body>
<div class="wrapper" id="contactPage">
<div class="content">

<?php
$token = md5(uniqid(rand(), TRUE));
$_SESSION['token'] = $token;
?>

<!--Contact Form-->
<form action="contact.php" id="contactForm" method="post" name="contactForm">
<input name="token" type="hidden" value="<?php echo $token; ?>">
<input name="ajax" type="hidden" value="1">

<div class="name">
<p>Your Name</p>
<input name="name" placeholder="Enter Name" required="" type="text">
</div>

<div class="email">
<p>Email Address</p>
<input name="email" placeholder="Enter Email" required="" type="email">
</div>

<div class="message">
<p>Message</p>
<textarea name="message" required=""></textarea>
</div>

<button id="submit" type="submit">Send</button>
</form>

<script type="text/javascript">
$("#contactForm").submit(function(event) {

event.preventDefault();
$submit = $(this).find('button[id="submit"]');
var posting = $.post($(this).attr('action'), $('#contactForm').serialize());

posting.done(function(data) {
$('span.error').remove();

if (data == "1") {
$submit.text('Sent. Thank You!');
$submit.addClass("sent");
$submit.attr('disabled', 'disabled');
} else {
$submit.after('<span style="display: inline-block; padding: 15px 5px; color: #bd3d3d">Failed to send the message, please try again later.</span>');
$submit.text('Try Again');
}
});
});
</script>
</body>
</html>

最佳答案

您要在 html 末尾添加 jquery,但在此之前您使用的是 jquery,因此 javascript 会因 Uncaught ReferenceError: $ is not Defined 中断。
尝试将此行移至标题:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

关于javascript - 联系表格在 iPhone 上无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21553098/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com