我想让我的 php 表单显示已选中的单选框。换句话说,当有人通过我的网站通过电子邮件与我联系时,我希望它显示他们勾选了哪个单选框。我已经尝试了一切,但无法让它工作!
到目前为止的 HTML 代码 -
<table width="308" border="0">
<label>
<input type="radio" name="servicetype[]" value="checkbox" id="Technical Support" />
Technical Support</label>
<label>
<input type="radio" name="servicetype[]" value="checkbox" id="Information Services" />
Information Services</label>
<tr>
<td align="left">
<input name="Submit" type="submit" id="Submit" class="contact-class2" value="Send"/>
</td>
</tr>
</table>
</form>
PHP 到目前为止
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'www.example.com';
$subject = 'hello';
$servicetype = join(", ", $_REQUEST["servicetype"]);
if (isset($_POST['servicetype'])) {
foreach ($_POST['servicetype'] as $key => $val) {
// do what you need
}
}
$body_message = ''.$field_message."\n"."\n";
$body_message .= 'From: '.$field_name;
$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">
window.location = 'Contact form.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
window.location = 'Contact form.html';
</script>
<?php
}
?>