2017-12-25 15 views
-3

ユーザーが連絡フォームを送信するときに、div alert-success内にユーザー名を表示するとします。どうすればいいですか、私を助けてくれますか? 私はindex.phpのページを持っているし、アクションスクリプトの先頭に ===== ===== index.phpの連絡先フォームを送信したときにユーザーの送信者名を表示する方法

<form method="post" action="mailer.php" class="contact-form">  
    <?php  
    if (isset($_GET['success'])) { 
     if ($_GET['success'] == 1) {   
    echo "<div class=\"alert-success success\">Thank you! Your 
    message has been sent.</div>";   
    }else{ 
    echo "<div class=\"alert-danger error\">Sorry! Something went 
    wrong, please try again.</div>"; 
     }  
    }  
?> 

mailer.php

+1

のようなフォームの連絡先、あなたが「ユーザ名」状態、(a)は、ユーザーが実際にあなたのサイトにサインインするか、または(b)あなたは、単純に人の名前を表示したいんあなたのフォームに入力として? –

+0

残りのコードはなぜイメージとして表示されますか?上記のように実際のコードを投稿したはずです。 –

+0

こんにちは。ちょうど私は入力として人の名前をフォームに表示したいと思います。 – atomant

答えて

0

使用session をmailer.phpこの

ようなあなたのアクションコード

<?php 
/* mailler.php */ 
session_start(); 

//Get the form fields, remove html tags and whitespace 
$name = strip_tags(trim($_POST['name'])); 
//... code after 

を呼び出します

/* mailler.php */ 
// ....code before 
// Send email 
mail($recipient, $subject, $email_content, $email_headers); 

//add this code 
$_SESSION['success'] = ['state'=> 1, 'name'=> $name]; 

//Redirect to the index.html page with form fragment 
header('Location: http://www.example.com/index.php#form'); 
exit(); 

そしてこの

<form method="post" action="mailer.php" class="contact-form">  
<?php  
    if (isset($_SESSION['success'])) { 
    if ($_SESSION['success']['state'] == 1) {   
     echo "<div class=\"alert-success success\">Thank you ". $_SESSION['success']['name'] ."! Your 
     message has been sent.</div>";   
    }else{ 
     echo "<div class=\"alert-danger error\">Sorry! Something went 
     wrong, please try again.</div>"; 
    } 
    unset($_SESSION['success']);   
    } 
    ?> 
+0

助けてもらえますが、うまくいきません。私は警告メッセージを見ることができません。私がフォームを提出すると、私は明確な接触フォームエリアを再び見るので、目に見えないエコーメッセージ – atomant

関連する問題