drrog9853 2018-12-11 17:38
浏览 57
已采纳

php单选按钮值(电子邮件表单)[重复]

This question already has an answer here:

I have a simple contact form that works great. I'm trying to add two radio buttons for a user to select. The choice they select will show up in the email I receive. How do I go about obtaining the value they select from the radio buttons?

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.
".
              "Last Name: $lastname.
".
              "Email: $email.
".
              "Company: $organization.
".
              "Phone: $phone.
".
              "Zip Code: $zip.
".
              "Message: $message.
";

$to ="email@email.com";
$headers = "From: $email_from 
";
$headers .= "Reply-To: $email 
";

mail($to,$email_subject,$email_body,$headers);

header("location: thankyou.html");
?>
</div>
  • 写回答

2条回答 默认 最新

  • dongzhang6021 2018-12-11 17:50
    关注

    Radio buttons are group together by having same name but different value. So the name would be IsClient and values will be Yes or 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>
    

    Then in php you will simply read the value of client like this

    $client = $_POST["client"];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?