html页面表单提交判断,如何在提交表单后在HTML页面中进行确认

嗨我有一个HTML文件,其中包含一个表单和一个接收html表单数据的php文件。 我想在PHP文件执行后在html文件(div容器内)中显示确认消息。到处寻找很多东西,但仍然没有得到答案。如何在提交表单后在HTML页面中进行确认

这里是我的HTML表单(enquiry.html)

Your Name

Your Email

Your Mobile

Your City

Remarks

Submit

test for form submission

$("#submitform").click(function() {

//code

$.post("enquiry.php", {

MasterInner_txtNamePost: MasterInner_txtName,

MasterInner_txtEmailPost: MasterInner_txtEmail,

MasterInner_txtMobilePost: MasterInner_txtMobile,

MasterInner_txtCityPost: MasterInner_lblCity,

MasterInner_txtRemarksPost: MasterInner_txtRemarks

},function(data) {

alert("Form submitted");

document.getElementByID(confirmID).innerHTML = "Submitted";

});

});

我无法理解,有什么用PHP编写设置“感谢您提交”,在HTML页面信息。

Enquiry.php文件

//使用error_reporting(0);

//if($_POST["w32apideftype"]!="")

//{

//echo $_POST["key"];

// Function for filtering input values.

function test_input($data)

{

$data = trim($data);

$data =stripslashes($data);

$data =htmlspecialchars($data);

return $data;

}

//echo "ths i stest";

// Initialize variables to null.

$s_name="ABC";// Sender Name

$s_email="[email protected]";//Sender's Email

$r_email="xyz ";//Recipient Email

$subject1="My subject";//Subject of mail

//Form Data vars

$f_name ="";

$f_email =""; // Sender's email ID

$f_message =""; // Sender's Message

$f_phone="";//Sender's Phone

$f_city="";//Sender's city

//Form data vars end

$nameError ="";

$emailError ="";

$f_phoneError="";

$f_cityError="";

$subjectError ="";

$f_messageError ="";

$successMessage =""; // On submittingform below function will execute.

if(isset($_POST['MasterInner_submit'])) { // Checking null values in message.

//echo "Submit button pressed";

if (empty($_POST["MasterInner_txtName"])){

$nameError = "Name is required";

//echo $nameError;

}

else

{

if (!preg_match("/^[a-zA-Z ]*$/",$f_name))

{

$nameError = "Only letters and white space allowed";

}

else

{

$f_name = test_input($_POST["MasterInner_txtName"]); // check name only contains letters and whitespace

//echo $name;

}

} // Checking null values inthe message.

if (empty($_POST["MasterInner_txtEmail"]))

{

$emailError = "Email is required";

//echo $emailError;

}

else

{

$f_email = test_input($_POST["MasterInner_txtEmail"]);

//echo $email;

} // Checking null values inmessage.

if (empty($_POST["MasterInner_txtRemarks"]))

{

$f_messageError = "Message is required";

$f_message="No Additional message";

//echo $f_messageError;

}

else

{

$f_message = test_input($_POST["MasterInner_txtRemarks"]);

//echo $f_message;

} // Checking null values inthe message.

if (empty($_POST["MasterInner_txtMobile"]))

{

$f_phoneError = "Genuine phone is required";

//echo $f_phoneError;

}

else

{

$f_phone = test_input($_POST["MasterInner_txtMobile"]);

//echo $f_phone;

} // Checking null values inmessage.

if ($_POST["MasterInner_txtCity"]=="Not Selected")

{

$f_cityError = "city is required";

//echo $f_cityError;

}

else

{

$f_city = test_input($_POST["MasterInner_txtCity"]);

//echo $f_city;

} // Checking null values inmessage.

if(!($f_name=='') && !($f_email=='') &&!($f_phone=='') &&!($f_city==''))

{ // Checking valid email.

if (preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$f_email))

{

$email=str_replace(",","",$f_email);

$header1 = 'MIME-Version: 1.0' . "\r\n";

$header1 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$header1 .= 'To: '.$r_email."\r\n";

$header1 .= 'From: '.$s_name.'' . "\r\n";

$header1 .= 'Cc:' . "\r\n";

$header1 .= 'Bcc:' . "\r\n";

/* Let's prepare the message for the e-mail */

//$msg = wordwrap($msg, 70, "\r\n");

$msg1 = '

Enquiry

'.$f_name.' sent a Enquiry

Name: '.$f_name.'
E-mail: '.$f_email.'
Phone: '.$f_phone.'
city: '.$f_city.'
Message: '.$f_message.'

';

/* Send the message using mail() function */

//echo "message1: - $msg and message 2 : - $msg1";

if(mail($s_email,$subject1,$msg1,$header1))

{

$successMessage = "Message sent successfully.......";

echo"Thank You";

header("location:".$_POST["w32apideftype"]);

}

}

else

{

$emailError = "Invalid Email";

//echo"Invalid Email";

}

}

}

//}

?>

请帮助,得到这个工作。

+0

请发布您的PHP文件以及 –

+0

如果您使用ajax将表单的详细信息提交给php,您可以等待回调状态,然后显示成功消息 - 您也可以回显一些数据从PHP到ajax说什么 - http://api.jquery.com/jquery.ajax/ - 在该页面上搜索(保存一些数据到服务器,并在用户完成后通知用户。) –

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在前端form,可以通过JavaScript来实现在密码和确认密码不一致时不提交表单的操作。 可以给确认密码输入框添加一个事件监听器,当确认密码的值改变时,就判断密码和确认密码的值是否相同,如果不同则禁止表单提交。以下是一个示例代码: ``` <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>注册</title> </head> <body> <h2>注册</h2> <form onsubmit="return validateForm()"> <label for="username">用户名</label> <input type="text" id="username"> <label for="password">密码</label> <input type="password" id="password"> <label for="confirm_password">确认密码</label> <input type="password" id="confirm_password" oninput="checkPassword()"> <button type="submit">注册</button> </form> <script> function checkPassword() { var password = document.getElementById("password").value; var confirm_password = document.getElementById("confirm_password").value; if (password !== confirm_password) { document.getElementById("confirm_password").setCustomValidity("密码和确认密码不一致"); } else { document.getElementById("confirm_password").setCustomValidity(""); } } function validateForm() { var password = document.getElementById("password").value; var confirm_password = document.getElementById("confirm_password").value; if (password !== confirm_password) { document.getElementById("confirm_password").setCustomValidity("密码和确认密码不一致"); return false; } else { document.getElementById("confirm_password").setCustomValidity(""); return true; } } </script> </body> </html> ``` 这段代码,`checkPassword()`函数会在确认密码输入框的值改变时调用,判断密码和确认密码的值是否相同,如果不同则设置确认密码输入框的`setCustomValidity`属性为一个错误提示信息。`validateForm()`函数会在表单提交时调用,判断密码和确认密码的值是否相同,如果不同则设置确认密码输入框的`setCustomValidity`属性为一个错误提示信息,并返回`false`阻止表单提交,否则返回`true`允许表单提交

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值