(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/>';
}
然后我这样做了:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些行将导致意外结果:
此方法将简单地将
$rsvp
的值分别设置为“YES”和“NO”。要测试等效性,您应该使用比较运算符==
:和
These lines will lead to unexpected results:
This method will simply set the value of
$rsvp
to 'YES' and 'NO' respectively. To test for equivalence, you should use the comparison operator==
:and