drrog9853
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
    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"];
    
    点赞 评论
  • douniao8687
    douniao8687 2018-12-11 17:49

    Use the same name for input type radio, then set the value. You can get the value by simply using $_POST['Your_Radio_Name']

    点赞 评论

相关推荐