0

送信時にリダイレクト機能を使用して、名前/メールフォームを機能させることができました。唯一の問題は、リダイレクト ページが読み込まれると、その上部にフォーム入力 (名前と電子メール) が表示されることです。

私がどこに落ちたのか、誰かわかりましたか?

<!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=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
 function submitForm() {
      var form = document.forms[0];
      if (form.name.value == '') { alert("Name?"); return; }
      if (form.email.value == '') { alert("Email?"); return; }

      apos = form.email.value.indexOf("@");
      dotpos = form.email.value.lastIndexOf(".");
      if (apos < 1 || dotpos - apos < 2) { alert("Correct email?"); return; }

      form.submit();
  }
</script>
<script src="fancybox/jquery.fancybox-1.3.1.pack.js" type="text/javascript"></script>
<link rel="stylesheet" href="fancybox/jquery.fancybox-1.3.1.css" type="text/css" media="screen"/>

<script type="text/javascript">
function PopIt() { 
    $("a#trigger").trigger('click');
    window.onbeforeunload = UnPopIt;
    return "Dont go."; 
}

function UnPopIt()  { /* nothing to return */ } 

$(document).ready(function() {
    window.onbeforeunload = PopIt;

    $("a#trigger").fancybox({
        'hideOnContentClick': false,
        'showCloseButton': false
    });

    $("a[id!=trigger]").click(function(){ window.onbeforeunload = UnPopIt; });
});
</script>

</head>
<body>

<div style="display: none;">
<a id="trigger" href="#popup">&nbsp;</a>
<div id="popup">
<div style="background-color:#ff3300;">
<form method="post" action="page2.php" name="popups" id="popups">
        <fieldset>
        <label for=name><span class="required">*</span> Name</label>
        <br />
        <input name="name" type="text" id="name" size="30" value="" /> 
        <br />
        <label for=email><span class="required">*</span> Email</label>
        <br />
        <input name="email" type="text" id="email" size="30" value="" />
        <br />
        <input type="button" value="Submit" class="btn" onclick="submitForm();">            
        </fieldset>  
        <br />
</form>
</div>        
</div>
</div>

<div id="content">Fa la la la la</div>
</div>
</body>
</html>

訪問者がデータを入力すると (終了時にトリガーされるポップアップ ウィンドウで)、送信ボタンを押した後、フォームはここにリダイレクトされます。

<? 
if($_POST['name']!="" and $_POST['email']!=""){

$headers    = "From: Acme";
$message    = 
strtoupper($_POST['name'])."
".strtoupper($_POST['email'])."
";
echo str_replace("\n","<br />", $message);
$headers2    = "From: Acme <ceo@acme.com>\nContent-Type: text/plain; charset=UTF-8;             format=flowed\nMIME-Version: 1.0\nContent-Transfer-Encoding: 8bit\nX-Mailer: PHP\n";
$message2    = "
Hello ".($_POST['name'])."   

";

mail("ceo@acme.com", "Freebies", $message, $headers);        
mail("$_POST[email]", "Gesundheit!", $message2, $headers2);

$myFile = "free.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "$_POST[name]*$_POST[email]*".$_SERVER['REMOTE_ADDR']."*".date("d-m-Y     H:i")."
";
fwrite($fh, $stringData);
fclose($fh);

}
?>
<!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=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
setTimeout(function(){
$("div#md").fadeIn("slow", function () {
});

}, 1000);
});
</script>
</head>
<body>
<div id="top"><a href="index.html"><img src="top.png" /></a></div>
<div id="wrapper" style="height:900px;">
<div id="content">Whoo-eee</div>
</div>
</body>
</html>

しかし、この page2.php の上部に表示されるフォーム情報 (名前とメール) がどのように、またはなぜあるのかわかりません...

4

2 に答える 2

0
echo str_replace("\n","<br />", $message);

page2 のこの行をコメントアウトします

于 2012-07-27T09:00:54.793 に答える
0

あなたはこの行を持っています

  echo str_replace("\n","<br />", $message);

2ページの上部にあるので、名前と電子メールで構成されるメッセージをエコーし​​ています

于 2012-07-27T08:58:42.450 に答える