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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?