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...
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'){
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With