【发布时间】:2020-10-19 18:08:37
【问题描述】:
这就是与 CSS 集成的 Html 页面、PHP 中的表单和对 js 脚本的调用。
<section class="contact-section">
<div class="container">
<div class="d-none d-sm-block mb-5 pb-4"></div>
<div class="row">
<div class="col-12">
<h2 class="contact-title">Inoltra qui la tua richiesta</h2>
</div>
<div class="col-lg-8">
<form class="form-contact contact_form" action="contact_process.php" method="post" id="contactForm" novalidate="novalidate">
<div class="row">
<div class="col-12">
<div class="form-group">
<textarea class="form-control w-100" name="message" id="message" cols="30" rows="9" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Inserisci il Messaggio'" placeholder="Inserisci il Messaggio"></textarea>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control valid" name="name" id="name" type="text" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Nome'" placeholder="Nome">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control valid" name="email" id="email" type="email" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Inserisci l'indirizzo mail'" placeholder="Email">
</div>
</div>
<div class="col-12">
<div class="form-group">
<input class="form-control" name="subject" id="subject" type="text" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Inserisci Oggetto'" placeholder="Inserisci Oggetto">
</div>
</div>
</div>
<div class="form-group mt-3">
<button type="submit" class="button button-contactForm boxed-btn">Invia</button>
<br><br>Questo sito è protetto dal sistema antispam Google Recaptcha.
<a href="https://policies.google.com/privacy">Privacy Policy</a> e <a href="https://policies.google.com/terms">Termini di servizio</a>
</div>
</form>
</div>
这是 PHP 中的联系表单
<?php
$to = " infoessebi-ingegneria@gmail.com";
$from = $_REQUEST['email'];
$name = $_REQUEST['name'];
$subject = $_REQUEST['subject'];
$number = $_REQUEST['number'];
$cmessage = $_REQUEST['message'];
$headers = "From: $from";
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$subject = "You have a new message from Site.";
$logo = 'img/logo.png';
$link = '#';
$body = "<!DOCTYPE html><html lang='en'><head><meta charset='UTF-8'><title>Express Mail</title></head><body>";
$body .= "<table style='width: 100%;'>";
$body .= "<thead style='text-align: center;'><tr><td style='border:none;' colspan='2'>";
$body .= "<a href='{$link}'><img src='{$logo}' alt=''></a><br><br>";
$body .= "</td></tr></thead><tbody><tr>";
$body .= "<td style='border:none;'><strong>Name:</strong> {$name}</td>";
$body .= "<td style='border:none;'><strong>Email:</strong> {$from}</td>";
$body .= "</tr>";
$body .= "<tr><td style='border:none;'><strong>Subject:</strong> {$csubject}</td></tr>";
$body .= "<tr><td></td></tr>";
$body .= "<tr><td colspan='2' style='border:none;'>{$cmessage}</td></tr>";
$body .= "</tbody></table>";
$body .= "</body></html>";
$send = mail($to, $subject, $body, $headers);
?>
这里我们有.js
$(document).ready(function(){
(function($) {
"use strict";
jQuery.validator.addMethod('answercheck', function (value, element) {
return this.optional(element) || /^\bcat\b$/.test(value)
}, "type the correct answer -_-");
// validate contactForm form
$(function() {
$('#contactForm').validate({
rules: {
name: {
required: true,
minlength: 2
},
subject: {
required: true,
minlength: 4
},
number: {
required: true,
minlength: 5
},
email: {
required: true,
email: true
},
message: {
required: true,
minlength: 20
}
},
messages: {
name: {
required: "Campo richiesto",
minlength: "il tuo nome deve consistere in almeno 2 caratteri"
},
subject: {
required: "Campo richiesto",
minlength: "il tuo oggetti deve avere almeno 4 caratteri"
},
number: {
required: "come on, you have a number, don't you?",
minlength: "your Number must consist of at least 5 characters"
},
email: {
required: "Campo richiesto"
},
message: {
required: "Campo richiesto",
minlength: "mi spiace ma non hai scritto un messaggio abbastanza lungo"
}
},
submitHandler: function(form) {
$(form).ajaxSubmit({
type:"POST",
data: $(form).serialize(),
url:"contact_process.php",
success: function() {
$('#contactForm :input').attr('disabled', 'disabled');
$('#contactForm').fadeTo( "slow", 1, function() {
$(this).find(':input').attr('disabled', 'disabled');
$(this).find('label').css('cursor','default');
$('#success').fadeIn()
$('.modal').modal('hide');
$('#success').modal('show');
})
},
error: function() {
$('#contactForm').fadeTo( "slow", 1, function() {
$('#error').fadeIn()
$('.modal').modal('hide');
$('#error').modal('show');
})
}
})
}
})
})
})(jQuery)
})
我的问题是为什么当所有上传的东西似乎都没有工作时?有什么线索吗?
请帮助我用我的小知识检查代码,但我找不到错误。
【问题讨论】:
-
什么不起作用?处理处理的 PHP 还是 javascript?你做了什么调试?
-
当我尝试查看问题所在时,我不知道是什么原因无法正常工作,调试软件似乎一切正常,所以我想知道我是否在某个地方遗漏了某些东西,或者我的服务器有问题
-
你到底指的是什么调试软件?例如,您是否使用浏览器中的开发人员工具来检查控制台错误和 AJAX 问题?确切地说,“没有任何工作”是什么意思?清楚地描述加载页面时发生的情况。你能看到表格吗?您可以输入文本并提交吗?当您尝试提交时会发生什么?验证有效吗?它是否尝试提交表单?数据是否到达 PHP。我还注意到您的 PHP 代码不会费心检查
mail()是否成功。 -
是的,我使用 chrome 的控制台查看页面中的所有脚本是否运行良好,看起来还可以。但我再说一遍,我完全是 php 和 jscript 的菜鸟,所以如果你有建议,他们将不胜感激
-
“当我尝试提交表单时没有任何反应”...这表明 JavaScript 失败(因此您有控制台错误,或者您的脚本未正确绑定到事件),或 AJAX 调用失败(其中通常会出现控制台错误,或者至少您可以在浏览器的网络工具中看到一些内容,这将表明调用 contact_process.php 发生了什么)。不过,“什么都没有发生”并不是对问题的有用描述 - 很可能,某事发生了,只是您还没有观察到它。
标签: javascript php html jquery twitter-bootstrap