我是网络开发的新手,我需要有关此联系表单的帮助。 我正在使用引导程序模板。
对不起发布错误的人,我是新来的,我对发布和编辑感到有些困惑。
这是我的PHP代码:
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message']);
// $human = intval($_POST['human']);
$from = 'Demo Contact Form';
$to = 'info@artgate.me';
$subject = 'Message from Contact Demo ';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Please enter your message';
}
//Check if simple anti-bot test is correct
//if ($human !== 5) {
// $errHuman = 'Your anti-spam is incorrect';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>
JS代码
function contactForm(){
$('.btn-submit').on('click',function(e){
var $this = $(this);
e.preventDefault();
$.ajax({
url : 'contact.php',
type : 'POST',
data : $this.closest('.contact-form').serialize(),
success : function(data){
if ($(data).is('.send-true')){
$this.addClass('loading').delay(650).queue(function(){
$this.addClass('success').addClass('loaded').dequeue();
});
} else {
$this.addClass('error');
}
$this.delay(500).queue(function(){
$this.removeClass('loaded').removeClass('loading').dequeue();
});
$this.delay(400).queue(function(){
if ($(data).is('.send-true')){
$this.removeClass('success').closest('.contact-form').trigger('reset');
} else {
$this.removeClass('error');
}
$this.dequeue();
});
}
});
});
}
答案 0 :(得分:0)
尝试从此处更改您的PHP:
if (isset($_POST["submit"])) {
到此:
if (isset($_POST["btn-submit"])) {
如果您将提交按钮命名为“btn-submit”,那么您的POST将包含一个名为“btn-submit”的变量
答案 1 :(得分:0)
在评论中,您说您的按钮的HTML代码是:
string ThisDir = "E:/AjkerDealLatest/images/Deals";
System.IO.Directory.CreateDirectory(ThisDir + "\\" + FolderNameHiddenField.Value);
ImageName = Request.Form.GetValues("name");
string path = Path.Combine("E:/AjkerDealLatest/images/Deals/"+ FolderNameHiddenField.Value, ImageName[0] + ".jpg");
file.SaveAs(path);
你需要的是一个&#34;名称&#34;属性。所以看起来应该是这样的:
<button type="submit" data-hover="Send" class="btn btn-default progress-button btn-submit"><span class="button-label">Send</span></button>
编辑完成后,您需要更改
<button type="submit" data-hover="Send" name="sendform" class="btn btn-default progress-button btn-submit"><span class="button-label">Send</span></button>
到
if (isset($_POST["submit"])) {
这应该让它现在起作用。
答案 2 :(得分:-1)
if(isset($ _ POST [&#34; submit&#34;])){
要 if(isset($ _ POST [&#34; submit_button_name&#34;])){
然后我会为你工作我认为