PHP表单处理〜问题与单选按钮chekced

时间:2015-05-25 09:44:18

标签: php forms radio-button

我正在尝试制作一个联系表单,我相信唯一的方法是通过PHP(所以当我的客户联系我时,我收到一封电子邮件。)这是一个非常简单的形式,但我无法得到表格给我发送单选按钮检查状态,并不知道如何。

这是我的HTML:

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$radio_yes = $_POST ['yes'];
$radio_no = $_POST ['no'];
$radio_I_am_already_in_it = $_POST ['I_am_already_in_it'];

$mail_to = 'my-email@my-site.com';
$subject = 'Hello, I am contacting you from your site. My name is '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$body_message .= 'True: '.$radio_yes;
$body_message .= 'True: '.$radio_no;
$body_message .= 'True: '.$radio_I_am_already_in_it;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
    alert('Thank you very much. I will do my best to reply to you within 24 hours.');
    window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('For some reason your message did not send. Please, do send me an e-   mail directly to fernando@fernandoalbertmedium.com');
window.location = 'contact.html';
</script>
<?php
}
?>

这是我的PHP:

textarea

表单工作正常,但单选按钮状态不会显示在我收到的电子邮件中。此外,由于某种原因,光标不会出现在{{1}}的开头,而是出现在第二行有一些缩进。你知道为什么吗?

2 个答案:

答案 0 :(得分:2)

您正试图通过$_POST键来获取无线电的价值,而不是这个无线电输入的名称,您需要这样做:

$radio_value = $_POST['mail-list'];

答案 1 :(得分:0)

$radio_checked = $_POST ['mail-list'];

他们得到的值是哪个单选按钮被选中,并且$ radio_checked值将根据这个值变成,就像你选中了一样