(PHP) html 表单中不同值的不同值

发布于 2024-11-24 01:41:34 字数 3897 浏览 0 评论 0原文

我有一个带有两个单选按钮的联系表。但我需要根据所选的单选按钮向客户端显示消息。 我会尝试更好地解释: 如果客户选择“是”单选按钮并按提交,则会出现一条消息“太棒了!我在那里看到你了!”我将收到一封包含所选选项的电子邮件。与“否”单选按钮相同,但它会显示“来吧...”消息。

这是我的 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/>';
}

然后我这样做了:

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>';
}

不起作用。实际上,当用户选择“否”单选按钮时,他会收到正确的消息,但是当他选择“是”单选按钮时,他会收到错误的消息(错误消息),但我正常收到表单电子邮件...

<强>编辑 好的!有用! 这就是我的做法:

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>";

}

我真的不知道它的编码是否正确,但它正在工作......

I have a contact form with two radio buttons. But I need to show messages to the client according with the chosen radio button.
I will try to explain better:
If the client choose the YES radio button and press submit, it will appear a message "Great! I see you there!" and I will receive an email with the chosen option.The same with the NO radio button, but it will appear a "C'mon..." as message.

Here is the php I have:

<?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/>';
}
?>

I have tried this, but is not working:

    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/>';
}

Then I did this:

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>';
}

Is not working. Actually, when the user chose the "no" radio button he receive the right message, but when he chose the "yes" radio button he receive the wrong message (the error message) but i receive the the form email normally...

Edit
Ok! It works!
Here is how I did:

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>";

}

I really don't know if it's coded right, but it's working...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瀞厅☆埖开 2024-12-01 01:41:34

这些行将导致意外结果:

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

此方法将简单地将 $rsvp 的值分别设置为“YES”和“NO”。要测试等效性,您应该使用比较运算符 ==

if($rsvp == 'YES'){

if($rsvp == 'NO'){

These lines will lead to unexpected results:

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

This method will simply set the value of $rsvp to 'YES' and 'NO' respectively. To test for equivalence, you should use the comparison operator ==:

if($rsvp == 'YES'){

and

if($rsvp == 'NO'){
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文