简体   繁体   English

html表单单选按钮和php

[英]html form radio buttons & php

I've made a html using html, and it contains some radio buttons. 我使用html制作了html,其中包含一些单选按钮。 How would I know which button is selected? 我怎么知道选择了哪个按钮? I need to send the selected option to my email, but I don't quite understand how it would be incorporated into my php script. 我需要将选定的选项发送到我的电子邮件中,但是我不太了解如何将其合并到我的php脚本中。 Thank you all so much! 非常感谢大家!

Below is my php script: 以下是我的PHP脚本:

    <?php

    $to = 'dinefour4@gmail.com';
    $subject = 'The subject';

    $name = $_POST['name'];
    $email = $_POST['email'];
    $option = $_POST['place']; <-- is this the way to know the selected button?
    $mobile = $_POST['mobile']; 

    $message = <<<EMAIL

    $name 
    $email
    $mobile

    EMAIL;

    $header = '$email';

    if($_POST) {
        mail($to, $subject, $message, $header);
    }

   ?>


    <div id="signup">
<form action="signup.php" method="POST" onsubmit="return validate()">
    <label name = "sutitle"> <font size="7"> sign up here!</font></label> <br/>
    <label ><font size="5" >Name:</font>
    <input type="text" name="name" required ></label><br />
    <label ><font size="5">Mobile:</font>
    <input type="text" name="mobile" required></label><br />
    <label ><font size="5">Email: </font>
    <input type="text" name="email" required></label><br />
    <label> <font size="5">Where to meet your Friends?</font><br/>
        <input type="radio" name="place" value="revelle" > <font size="5">Revelle  </font><br>
        <input type="radio" name="place" value="muir"> <font size="5">Muir  </font><br>
        <input type="radio" name="place" value="warren"> <font size="5">Warren </font><br>
        <input type="radio" name="place" value="erc" > <font size="5">ERC </font><br>
        <input type="radio" name="place" value="village"> <font size="5">The Village </font><br>
    </label>
    <input type="submit" value="Submit">
</form>

 <?php

$to = 'dinefour4@gmail.com';
$subject = 'The subject';

$name = $_POST['name'];
$email = $_POST['email'];
$option = ""
if(isset($_POST['place']))
{
    $option = $_POST['place']; 
}
$mobile = $_POST['mobile']; 

$message = <<<EMAIL

$name 
$email
$mobile

EMAIL;

$header = '$email';

if($_POST) {
    mail($to, $subject, $message, $header);
}

?>

<div id="signup">
<form action="signup.php" method="POST" onsubmit="return validate()">
<label name = "sutitle"> <font size="7"> sign up here!</font></label> <br/>
<label ><font size="5" >Name:</font>
<input type="text" name="name" required ></label><br />
<label ><font size="5">Mobile:</font>
<input type="text" name="mobile" required></label><br />
<label ><font size="5">Email: </font>
<input type="text" name="email" required></label><br />
<label> <font size="5">Where to meet your Friends?</font><br/>
    <input type="radio" name="place" value="revelle" > <font size="5">Revelle  </font><br>
    <input type="radio" name="place" value="muir"> <font size="5">Muir  </font><br>
    <input type="radio" name="place" value="warren"> <font size="5">Warren </font><br>
    <input type="radio" name="place" value="erc" > <font size="5">ERC </font><br>
    <input type="radio" name="place" value="village"> <font size="5">The Village </font><br>
</label>
<input type="submit" value="Submit">

If the radio button is selected, then it will set in '$option' variable. 如果选择了单选按钮,则它将在“ $ option”变量中设置。 Otherwise '$option' variable will be empty. 否则“ $ option”变量将为空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM