2017-02-22 17 views
0

を郵送するラジオボタンを追加: 私はHTMLフォームを持つフォーム

<form name="sentMessage" id="contactForm" novalidate> 
 
    <div class="row control-group"> 
 
    <div class="form-group col-xs-12 floating-label-form-group controls"> 
 
     <label>Name</label> 
 
     <input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name."> 
 
     <p class="help-block text-danger"></p> 
 
    </div> 
 
    </div> 
 
    <div class="row control-group"> 
 
    <div class="form-group col-xs-12 floating-label-form-group controls"> 
 
     <label>Email Address</label> 
 
     <input type="email" class="form-control" placeholder="Email Address" id="email" required data-validation-required-message="Please enter your email address."> 
 
     <p class="help-block text-danger"></p> 
 
    </div> 
 
    </div> 
 
    <div class="row control-group"> 
 
    <div class="form-group col-xs-12 floating-label-form-group controls"> 
 
     <label>Address</label> 
 
     <input type="text" class="form-control" placeholder="Address" id="address" required data-validation-required-message="Please enter your street address."> 
 
     <p class="help-block text-danger"></p> 
 
    </div> 
 
    </div> 
 
    <div class="row control-group"> 
 
    <div class="form-group col-xs-12 floating-label-form-group controls"> 
 
     <label>Postcode</label> 
 
     <input type="text" class="form-control" placeholder="Postcode" id="postcode" required data-validation-required-message="Please enter your postcode."> 
 
     <p class="help-block text-danger"></p> 
 
    </div> 
 
    </div> 
 
    <div class="row control-group"> 
 
    <div class="form-group col-xs-12 floating-label-form-group controls"> 
 
     <label>Cocktails</label> 
 
     <textarea rows="5" class="form-control" placeholder="Please enter which cocktails you would like to order" id="message" required data-validation-required-message="Please enter which cocktails you would like to order."></textarea> 
 
     <p class="help-block text-danger"></p> 
 
    </div> 
 
    </div> 
 
    <br> 
 
    <div id="success"></div> 
 
    <div class="row"> 
 
    <div class="form-group col-xs-12"> 
 
     <button type="submit" class="btn btn-success btn-lg">Send</button> 
 
    </div> 
 
    </div> 
 
</form>

それは

<?php 

if(empty($_POST['name'])  || 
    empty($_POST['email'])  || 
    empty($_POST['address'])   || 
    empty($_POST['postcode'])  || 
    empty($_POST['message']) || 
    !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) 
    { 
    die("No arguments Provided!"); //any text other than 'success' will be considered fail. 
    } 

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$address = $_POST['address']; 
$postcode = $_POST['postcode']; 
$message = $_POST['message']; 

// Create the email and send the message 
$to = ''; 
$email_subject = "subject: $name"; 
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nAddress: $address\n\nPostcode: $postcode\n\nMessage:\n$message"; 
$headers = "From: [email protected]\n"; 
$headers .= "Reply-To: $email_address"; 

/*** check if the mail() function was successful ***/ 
if(mail($to,$email_subject,$email_body,$headers)){ 
    die("success"); //the ajax code will use 'success' as the trigger to confirm email was sent 
}else{ 
    die("email failed"); 
} 

があり、私のメールアドレスに詳細を送信しますPHPファイルにリンクされていますラジオボタンのオプションをフォームに追加することができ、クリックされた場合は自分のメールにも送信されます。

答えて

0

はい、フォームにラジオボタンを簡単に追加できます。私はそのようにする方法の簡単な例を示し、それを使ってあなたのものを更新することができます。一つの値だけが送信されるよう

<form> 
    <input type="radio" name="gender" value="male" checked> Male<br> <!-- make sure atleast one is checked to ensure that atleast some data will be sent to your email --> 
    <input type="radio" name="gender" value="female"> Female<br> 
    <input type="radio" name="gender" value="other"> Other 
</form> 
0

HTML

<input type="radio" name="radio" value="option1" checked="checked" /> Option1<br/> 
<input type="radio" name="radio" value="option2" /> Option2 

名は、すべての無線入力に対して同じである必要があります。

PHPで

PHP

$radiovalue = $_POST['radio']; //be careful with name

+0

を値を取得するために私がボタンに追加ラジオボタンを持っているし、フォームの詳細は私の電子メールに送信されたときに言って価値がありますラジオだが、どのボタンがチェックされたのかわからない。 –

+0

'あなたのユーザは
'あなたのオプションを 'value'の中に置き、スペースの代わりに' _'を使用しようとします。 valueフィールドの中に何を入れても、入力タグの外側にテキストが表示されますが、両方とも同じですが、 'value'にスペース**を入れないようにしてください –