PHP提交按钮更改

时间:2015-10-12 21:04:53

标签: javascript php jquery

所以我得到了这段代码:

<?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. 正确发送邮件后,我希望按钮更改&#34;发送&#34;到&#34; MSG发送&#34; (也许可以将按钮颜色更改为绿色)

  3. 我该怎么做这些事情?

    任何链接到源的机会我都可以学习如何编写代码吗? 谢谢!

2 个答案:

答案 0 :(得分:0)

  1. 要在提交后保持同一页面,只需在表单标记中填写action="",或者您可以完全停止操作。
  2. 要更改按钮文字,您可以使用javascript document.getElementById("buttonId").value= "MSG";

答案 1 :(得分:0)

您可以使用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!");
       }
     }
});

A tutorial is here.

这两个链接很有用。

https://api.jquery.com/addclass/

http://api.jquery.com/replacewith/

相关问题