2011-07-12 31 views
3

我有一個帶有兩個單選按鈕的聯繫表單。但我需要根據所選的單選按鈕向客戶端顯示消息。 我會盡力解釋一下: 如果客戶端選擇YES單選按鈕並按提交,它會顯示一條消息「太棒了!我在那裏見你!」我會收到一封帶有選擇選項的電子郵件。與NO單選按鈕相同,但它會顯示「C'mon ...」作爲消息。(PHP)HTML格式的不同值的不同值。這是可能的?

這裏是PHP的我:

<?php 
if(isset($_POST['enviar'])) { 
    $remetente = "[email protected]"; 
    $destinatario = "[email protected]"; 
    $assunto = "Subject"; 
    $data = date("d/m/y"); 
    $hora = date("H:i"); 
    $charset = $_POST['charset']; 
    $nome = $_POST['nome']; 
    $email = $_POST['email']; 

    //This is the radio button value that i want to put conditionals. 
    $rsvp = $_POST['rsvp']; 
    $navegador = $_SERVER['HTTP_USER_AGENT']; 
    $ip = $_SERVER['REMOTE_ADDR']; 
    $corpo = utf8_decode("Data: ".$data."<br />Hora: ".$hora."<br />Nome: ".$nome."<br />E-mail: ".$email."<br />Ip: ".$ip."<br />Browser: ".$navegador."<br />RSVP: ".$rsvp."\r\n"); 

    $headers = "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-type: text/html; charset=".$charset."\r\n"; 
    $headers .= "Reply-To: ".$remetente."\r\n"; 

    $headers .= "From: ".$remetente."\r\n"; 


    //This is the part that i think it has to be changed. 
    if(mail($destinatario, $assunto, $corpo, $headers)) { 
     echo '<meta http-equiv="refresh" content=0;url=message_sended.php/>'; 
    } else { 
     echo '<meta http-equiv="refresh" content=0;url=error.php/>'; 
    } 
} else { 
    echo '<meta http-equiv="refresh" content=0;url=error.php/>'; 
} 
?> 

我已經試過這一點,但沒有工作...

if(mail($destinatario, $assunto, $corpo, $headers)) { 
     if($rsvp = 'YES'){ 
      echo '<meta http-equiv="refresh" content=0;url=message_sended_YES.php/>'; 
     } else { 
      echo '<meta http-equiv="refresh" content=0;url=error.php/>'; 
     } 
    } else { 
     echo '<meta http-equiv="refresh" content=0;url=error.php/>'; 
    } 

    if($rsvp = 'NO'){ 
     echo '<meta http-equiv="refresh" content=0;url=message_sended.php_NO/>'; 
    } else { 
     echo '<meta http-equiv="refresh" content=0;url=error.php/>'; 
    } 
} else { 
    echo '<meta http-equiv="refresh" content=0;url=error.php/>'; 
} 

PS:這是我第一次問的問題#1 .. 。希望你們明白我的苦衷

編輯: 我這樣做:

if(mail($destinatario, $assunto, $corpo, $headers)) { 
    if($rsvp == 'sim'){ 
     echo '<meta http-equiv="refresh" content=0;url=sim.php>'; 
    } 
    else 
    { 
     echo '<meta http-equiv="refresh" content=0;url=contato_mensagem_erro.php>'; 
    } 
} 
else 
{ 
    echo '<meta http-equiv="refresh" content=0;url=contato_mensagem_erro.php>'; 
} 

if($rsvp == 'nao'){ 
    echo '<meta http-equiv="refresh" content=0;url=nao.php>'; 
} 
else 
{ 
    echo '<meta http-equiv="refresh" content=0;url=contato_mensagem_erro.php>'; 
} 
} 
else 
{ 
echo '<meta http-equiv="refresh" content=0;url=contato_mensagem_erro.php>'; 
} 

不工作。實際上,當用戶選擇「否」單選按鈕時,他會收到正確的消息,但是當他選擇「是」單選按鈕時,他會收到錯誤消息(錯誤消息),但我通常會收到表單電子郵件...

編輯2 好的!有用! 這裏是我做的事:

if(mail($destinatario, $assunto, $corpo, $headers)) { 

if($rsvp == "sim"){ 

    echo 

    header('Location: sim.php/'); 

} 

else 

{ 

    echo "<meta http-equiv='refresh' content=0;url=contato_mensagem_erro.php>"; 

} 

} 

else 

{ 

    echo "<meta http-equiv='refresh' content=0;url=contato_mensagem_erro.php>"; 

} 

if($rsvp == "nao"){ 

    echo header('Location: nao.php/'); 

} 

else 

{ 

    echo "<meta http-equiv='refresh' content=0;url=contato_mensagem_erro.php>"; 

} 

} 

else 

{ 

    echo "<meta http-equiv='refresh' content=0;url=contato_mensagem_erro.php>"; 

} 

我真的不知道,如果它的編碼正確的,但它的工作...

+2

你是什麼意思它不工作?上面的代碼會引發一個語法錯誤。如果你先解決這個問題會發生什麼? – madflow

+0

在Dreamweaver中輸入時沒有sintax錯誤。 –

+0

該代碼已被編輯/修正在此期間;) – madflow

回答

5

這些行會導致意想不到的結果:

if($rsvp = 'YES'){ 
if($rsvp = 'NO'){ 

這種方法將簡單地將$rsvp的值分別設置爲「是」和「否」。爲了測試是否相等,你應該使用比較運算==

if($rsvp == 'YES'){ 

if($rsvp == 'NO'){ 
+0

Gerorge,謝謝你的回答!你可以在我原來的問題中編輯一下嗎? –

+0

@ÉrNica:我編輯了你新貼的代碼插入縮進。這揭示了這個問題:你的代碼中存在着無法比擬的大括號。你可以使用縮進和包圍來確保你的if/else語句按照你的期望工作嗎? –

+0

是的,我們可以! :D 謝謝喬治! 我會發布結果。 –