PHP提交按钮更改

PHP Submit button change

本文关键字:按钮 提交 PHP      更新时间:2023-09-26

所以我得到了这个代码:

<?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>

我想做的是:

  1. 在我点击这个表单的提交按钮后,我想保持在同一页面

  2. 在消息正确发送后,我希望按钮将文本从"发送"更改为"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/

  1. 为了在提交后保持在同一页面上,您只需在表单标签中填写action="",或者您可以完全忽略动作。
  2. 要更改按钮文本,您可以使用javascript document.getElementById("buttonId").value= "MSG";