PHP提交按钮更改
PHP Submit button change
所以我得到了这个代码:
<?php
// -----------------------------------------
// The Web Help .com
// -----------------------------------------
// remember to replace your@email.com with your own email address lower in this code.
// load the variables form address bar
$name = $_REQUEST["name"];
$message = $_REQUEST["message"];
$from = $_REQUEST["from"];
$verif_box = $_REQUEST["verif_box"];
// remove the backslashes that normally appears when entering " or '
$name = stripslashes($name);
$message = stripslashes($message);
$from = stripslashes($from);
// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
// if verification code was correct send the message and show this page
$message = "Name: ".$name."'n".$message;
$message = "From: ".$from."'n".$message;
mail("myMail@gmail.com", 'MSG from site', $_SERVER['REMOTE_ADDR']."'n'n".$message, "From: $from");
// delete the cookie so it cannot sent again by refreshing this page
setcookie('tntcon','');
} else {
// if verification code was incorrect then return to contact page and show error
header("Location:".$_SERVER['HTTP_REFERER']."?&from=$from&message=$message&wrong_code=true");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PHP Contact Form Redirect</title>
</head>
<body>
</body>
</html>
我想做的是:
在我点击这个表单的提交按钮后,我想保持在同一页面
在消息正确发送后,我希望按钮将文本从"发送"更改为"MSG发送"(并且可能将按钮颜色更改为绿色)
我该怎么做这些事?
任何机会链接到一个源,我可以学习如何编码这个?谢谢!
您可以使用jQuery来完成此操作。下面是一个起点。
var dataString = $("#contactform").serialize();
$.ajax({
type: "POST",
url: "../public/txtmailer-v3.php",
data: dataString,
cache: false,
success: function(html){
//insert html and css edits here
}, error: function(html){
alert("Error sending email!");
}
}
});
教程在这里。
这两个链接将是有用的。
https://api.jquery.com/addclass/http://api.jquery.com/replacewith/- 为了在提交后保持在同一页面上,您只需在表单标签中填写
action=""
,或者您可以完全忽略动作。 - 要更改按钮文本,您可以使用javascript
document.getElementById("buttonId").value= "MSG";
相关文章:
- 使用按钮和单选按钮提交表单,但始终使用相同的值
- 使用回车按钮提交文本框表单
- 清除按钮提交后的文本区域
- 单击按钮提交输入字段值
- 我可以从 Rails 4 中的按钮提交传递参数吗?
- 如何使用inputtype=按钮提交表单
- 使用两个按钮(提交按钮和普通按钮),它们应该以不同的方式提交相同的表单
- 使用jquery UI next按钮提交输入字段值,php将返回结果
- AJAX-按钮提交以更新表单
- 在向导表单中使用按钮提交值的最佳方式
- 如何阻止按钮提交
- 使用提交按钮提交表单,而不是页面上的其他按钮
- 用于两个功能的Javascript按钮.提交&单击
- 如何使用一个提交按钮提交三个表单
- 如何使用按钮提交表单
- 如何查看从 javascript 中的表单按钮提交调用的 php 文件中的回显
- 不能在按钮提交处理程序中使用变量
- 由多个按钮提交的一个模式引导表单
- 为什么<输入类型=“按钮”>提交表单
- 使用表单外的按钮提交表单