Select menu problem

Hello guys!
I’m doing a website, and i would like to make a select menu. If somebody fill the parts i mean name phone number and email, than the “customer” need to select a choice.
That’s done, now the problem is, some reason when i got the email, its showing me only: Select
and i need the selected menu to show.
I have a mail config php but i don’t really know what’s the problem

<div>
				  <select class="form-control" id="select" type="sel" placeholder="Válassz*" required="required" data-validation-required-message="Kérlek válassz." name="dropdown" >
<option value="Laptop">Laptop</option>
<option value="Szamitogep">Számítógép</option>
<option value="iPhone">iPhone</option>
<option value="Samsung">Samsung</option>
<option value="Egyeb">Egyéb</option>
</select>
				  </div>

<?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 = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
$dropdown = strip_tags(htmlspecialchars($POST['dropdown']));
   
// Create the email and send the message
$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.
$email_subject = "my 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\nPhone: $phone\n\nMessage:\n$message\n\nSelect: $value";
$headers = "[email protected]"; // This is the email address the generated message will be from. We recommend using something like [email protected].
$headers .= "Reply-To: $email_address";   
mail($to,$email_subject,$email_body,$headers);
return true;         
?>

thanks if you help me!

Compare some things,

$_POST[‘message’]

vs

$POST[‘dropdown’]

i tryed everything, nothing gonna work :confused:

What’s the difference in the two things I posted from your code?

nothing, just not working. this is what i get from the email:
You have received a new message from your website contact form.

Here are the details:

Name: myname

Email: [email protected]

Phone: 7xxxxxxx

Message:
Sg

Select:

thats it

There must be a language barrier or something. Last chance, what did I tell you to look at?

i changed the words to english (because its hungarian) and the same issue :confused:

Again,

Compare some things,

$_POST[‘dropdown’]

vs

$POST[‘dropdown’]

1 Like

enable error reporting and you will get a definitive message for this. Also this should be the default setting for your development machine

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Mi a különbség a kódodban közzétett két dologban?

$_POST[‘dropdown’]
vs
$POST[‘dropdown’]

Please Change this :
$dropdown = strip_tags(htmlspecialchars($POST['dropdown']));
to
$dropdown = strip_tags(htmlspecialchars($_POST[‘dropdown’]));

That is what @chorn was trying to tell you. Please observe the coding. Sorry for interfering

@shruti, your comment is fine, not interfering at all. I was just hoping that they would see what was said on their own…

Thank you for your help, but I have the same problem :confused:

Hello,

examine your code more carefully, which is a good reason to write code with structure and organization. Problem solving requires step-by-step examination of code to determine the cause(s) of an error. You should notice the following code:

$email_body: 
You have received a new message from your website contact form
Here are the details:
Name: $name
Email: $email_address
Phone: $phone
Message: $message
Select: $value

you specify $value instead of, i guess, $dropdown

where are you storing a variable named $value?

I use the only the select menu. i show my files in here:
This is the index file only the select menu:

  <!-- Contact -->
  <section id="contact">
    <div class="container">
      <div class="row">
        <div class="col-lg-12 text-center">
          <h2 class="section-heading text-uppercase">Kapcsolat</h2>
          <h3 class="section-subheading text-muted">Ne habozz! Vedd fel velem a kapcsolatot!</h3>
        </div>
      </div>
      <div class="row">
        <div class="col-lg-12">
          <form id="contactForm" name="sentMessage" novalidate="novalidate">
            <div class="row">
              <div class="col-md-6">
                <div class="form-group">
                  <input class="form-control" id="name" type="text" placeholder="Neved*" required="required" data-validation-required-message="Kérlek add meg a neved.">
                  <p class="help-block text-danger"></p>
                </div>
                <div class="form-group">
                  <input class="form-control" id="email" type="email" placeholder="E-mail címed *" required="required" data-validation-required-message="Kérlek add meg az e-mail címed.">
                  <p class="help-block text-danger"></p>
                </div>
                <div class="form-group">
                  <input class="form-control" id="phone" type="tel" placeholder="Telefonszámod *" required="required" data-validation-required-message="Kérlek add meg a telefonszámod.">
                  <p class="help-block text-danger"></p>
                </div>
				  <div>
				  <select class="form-control" size=1 id="dropdown1" type="dropdown" name="dropdown" >
<option value="Laptop">Laptop</option>
<option value="Szamitogep">Számítógép</option>
<option value="iPhone">iPhone</option>
<option value="Samsung">Samsung</option>
<option value="Egyeb">Egyéb</option>
</select> 
					  
              </div>
				
				  </div>
              <div class="col-md-6">
                <div class="form-group">
                  <textarea class="form-control" id="message" placeholder="Üzenet *" required="required" data-validation-required-message="Kérlek írd le az üzeneted."></textarea>
                  <p class="help-block text-danger"></p>
                </div>
              </div>
              <div class="clearfix"></div>
              <div class="col-lg-12 text-center">
                <div id="success"></div>
                <button id="sendMessageButton" class="btn btn-primary btn-xl text-uppercase" type="submit">Üzenet küldése</button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </section>

this is the script:

$(function() {

  $("#contactForm input,#contactForm textarea").jqBootstrapValidation({
    preventSubmit: true,
    submitError: function($form, event, errors) {
      // additional error messages or events
    },
    submitSuccess: function($form, event) {
      event.preventDefault(); // prevent default submit behaviour
      // get values from FORM
      var name = $("input#name").val();
      var email = $("input#email").val();
      var phone = $("input#phone").val();
      var message = $("textarea#message").val();
      var firstName = name; // For Success/Failure Message
      // Check for white space in name for Success/Fail message
      if (firstName.indexOf(' ') >= 0) {
        firstName = name.split(' ').slice(0, -1).join(' ');
      }
      $this = $("#sendMessageButton");
      $this.prop("disabled", true); // Disable submit button until AJAX call is complete to prevent duplicate messages
      $.ajax({
        url: "././mail/contact_me.php",
        type: "POST",
        data: {
          name: name,
          phone: phone,
          email: email,
          message: message
        },
        cache: false,
        success: function() {
          // Success message
          $('#success').html("<div class='alert alert-success'>");
          $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
            .append("</button>");
          $('#success > .alert-success')
            .append("<strong>Your message has been sent. </strong>");
          $('#success > .alert-success')
            .append('</div>');
          //clear all fields
          $('#contactForm').trigger("reset");
        },
        error: function() {
          // Fail message
          $('#success').html("<div class='alert alert-danger'>");
          $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
            .append("</button>");
          $('#success > .alert-danger').append($("<strong>").text("Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!"));
          $('#success > .alert-danger').append('</div>');
          //clear all fields
          $('#contactForm').trigger("reset");
        },
        complete: function() {
          setTimeout(function() {
            $this.prop("disabled", false); // Re-enable submit button when AJAX call is complete
          }, 1000);
        }
      });
    },
    filter: function() {
      return $(this).is(":visible");
    },
  });

  $("a[data-toggle=\"tab\"]").click(function(e) {
    e.preventDefault();
    $(this).tab("show");
  });
});

/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
  $('#success').html('');
});

and this is the contact_me.php file now:

<?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;
   }
   
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
$dropdown = strip_tags(htmlspecialchars($_POST['dropdown']));
$value_from_dropdown = $_POST['dropdown'];
  



// Create the email and send the message
$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.
$email_subject = "subject :  $name";
$email_body =  "Valaki küldött e-mailt.\n\n"."Ezek az adatok:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message\n\nSelect:$dropdown";
$fields = array('name' => 'Name', 'surname' => 'Surname', 'need' => 'Need', 'email' => 'Email', 'message' => 'Message'); 
$headers = "[email protected]"; // This is the email address the generated message will be from. We recommend using something like [email protected].
$headers .= "Reply-To: $email_address";   
mail($to,$email_subject,$email_body,$headers);
return true;         
?>

and still not working :confused:

But now you have two variables which represent the select option named dropdown:

$dropdown = strip_tags(htmlspecialchars($_POST['dropdown']));
$value_from_dropdown = $_POST['dropdown'];

just use one and preferably this one:

$dropdown = strip_tags(htmlspecialchars($_POST['dropdown']));

And looking at your ajax script:

      $.ajax({
        url: "././mail/contact_me.php",
        type: "POST",
        data: {
          name: name,
          phone: phone,
          email: email,
          message: message
        },

where are you passing this value?

i change the script, and deleted this: $value_from_dropdown = $_POST['dropdown'];

this is the script now:

var name = $(“input#name”).val();
var email = $(“input#email”).val();
var phone = $(“input#phone”).val();
var message = $(“textarea#message”).val();
var dropdown = $(“select#dropdown”).val();
var firstName = name; // For Success/Failure Message
// Check for white space in name for Success/Fail message
if (firstName.indexOf(’ ‘) >= 0) {
firstName = name.split(’ ‘).slice(0, -1).join(’ ');
}
$this = $("#sendMessageButton");
$this.prop(“disabled”, true); // Disable submit button until AJAX call is complete to prevent duplicate messages
$.ajax({
url: “././mail/contact_me.php”,
type: “POST”,
data: {
name: name,
phone: phone,
email: email,
message: message,
select: dropdown

this is the email

Valaki küldött e-mailt.

Ezek az adatok:

Name: myname

Email: [email protected]

Phone: 7xxxxxxx

Message:
test

Dropdown:

so i mean still doesn’t work :confused:

I bet it is working and you are looking in the wrong place. You seem to be mindlessly changing your code without understanding why.

$value_from_dropdown = $_POST[‘dropdown’];

You don’t send anything in with this key.

on the processing page, add,

print_r($_POST);

You can see what gets sent. Guessing is going to keep you where you are.

1 Like

while we are at it, let’s look at your html too:

<select class="form-control" size=1 id="dropdown1" type="dropdown" name="dropdown" >

a select form input does not carry a type attribute
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select

furthermore, examine your (type excluded) code:

<select class="form-control" size=1 id="dropdown1" name="dropdown" >

you need to understand basic html here. a name and an id can be attached to an element for access to the element by name or id. one must access the element by the same value attached to name or id

you are not examining your code. you are just trying things and reporting back.
vide the comment from @astonecipher

So, what does the following code do?

var name = $(“input#name”).val();
var email = $(“input#email”).val();
var phone = $(“input#phone”).val();
var message = $(“textarea#message”).val();
var dropdown = $(“select#dropdown”).val();

is the pound sign specifying an id?
so you have “1” change left to make a difference in the outcome of the submission.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service