This question already has an answer here:
I have two radio buttons in my contact form like this:
<div class="field form-inline radio">
<input class="radio" type="radio" name="response" value="ATTENDING" /><span>Blalala 1</span>
</div>
<div class="field form-inline radio">
<input class="radio" type="radio" name="response" value="NOT ATTENDING" /><span>Blablabla 2</span>
</div>
/* ... */
<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="Write your name">
<p class="help-block text-danger"></p>
</div>
and then some generic contact_me.php from the internet like this:
<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
$response = $_POST['response'];
/* ... */
$email_body = "You have received a new message from your website contact form.
"."Here are the details:
Name: $name
Email: $email_address
Phone: $phone
Response: $response
Message:
$message";
/* ... */
But the response-field remains empty always in the email I get, whatever try. I google a lot, nothing helped. I hope you can!
The rest of the code is from template and it works, two radio buttons I added and cannot get to work.
</div>
I hope you are looking for this:
Your HTML Form:
<form method='post' action=''>
<input type="text" name="name" value="">
<input type="text" name="email" value="">
<input type="text" name="phone" value="">
<input type="text" name="message" value="">
<input type="radio" name="response" value="Attend">Attend
<input type="radio" name="response" value="Not Attend">Not Attend
<input type="submit" name="submit" value="Submit"></form>
And PHP Code:
<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
else {
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
$response = $_POST['response'];
/* email body */
$email_body = "You have received a new message from your website contact form.
Here are the details:
Name: $name
Email: $email_address
Phone: $phone
Response: $response
Message:
$message";
$header = "From: noreply@example.com
";
$header.= "MIME-Version: 1.0
";
$header.= "Content-Type: text/html; charset=ISO-8859-1
";
$header.= "X-Priority: 1
";
mail(to, subject, $email_body, $header);
}
?>
What I change: