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 求指导ADS低噪放设计
  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存