我有一个简单的联系方式,效果很好。我正在尝试添加两个单选按钮供用户选择。他们选择的选项将显示在我收到的电子邮件中。如何获得从单选按钮中选择的值?
html:
<div class="form-row">
<div class="form-group col-md-">
<label class="radio-inline "><input type="radio" name="current" checked>I'm an existing client</label>
</div>
<div class="form-group col-md-6 pb-2">
<label class="radio-inline "><input type="radio" name="not-current">I'm not a client yet</label>
</div>
</div>
PHP:
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$organization = $_POST['organization'];
$phone = $_POST['phone'];
$zip = $_POST['zip'];
$message = $_POST['message'];
$email_from = 'Contact Us';
$email_subject = 'New Message';
$email_body = "First Name: $firstname.\n".
"Last Name: $lastname.\n".
"Email: $email.\n".
"Company: $organization.\n".
"Phone: $phone.\n".
"Zip Code: $zip.\n".
"Message: $message.\n";
$to ="email@email.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("location: thankyou.html");
?>
答案 0 :(得分:0)
对输入类型单选使用相同的名称,然后设置值。 您只需使用$ _POST ['Your_Radio_Name']
即可获取值答案 1 :(得分:0)
单选按钮通过名称相同但值不同的方式组合在一起。因此名称为IsClient,值将为Yes或No
<div class="form-row">
<div class="form-group col-md-">
<label class="radio-inline">
<input type="radio" name="client" value="current" checked>I'm an existing client
</label>
</div>
<div class="form-group col-md-6 pb-2">
<label class="radio-inline ">
<input type="radio" name="name="client" value="not-current">I'm not a client yet
</label>
</div>
</div>
然后在php中,您将像这样简单地读取client的值
$client = $_POST["client"];