-2

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.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nResponse: $response\n\nMessage:\n$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.

stmas
  • 1
  • 2

1 Answers1

0

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. \n\n
Here are the details: \n\n
Name: $name \n\n
Email: $email_address \n\n
Phone:  $phone \n\n
Response: $response \n\n
Message: \n $message";


$header = "From: noreply@example.com\r\n"; 
$header.= "MIME-Version: 1.0\r\n"; 
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
$header.= "X-Priority: 1\r\n";

mail(to, subject, $email_body, $header);
}

?>

What I change:

  • Adding proper input names for all field.
  • move success block in else condition
  • add email headers
devpro
  • 16,184
  • 3
  • 27
  • 38