J
J
John Gault2015-11-28 20:44:36
PHP
John Gault, 2015-11-28 20:44:36

Adding select in php mandrel form?

I have not worked with php before, so please do not judge for simplicity. There is:

<form id="form">
    <input type="text" name="name" placeholder="Ваше имя" required /><br />
    <input type="text" name="phone" placeholder="Ваш телефон" required /><br />

    <select>
      <option value="0">Ващ выбор</option>
      <option value="1">Выбор 1</option>
      <option value="2">Выбор 2</option>
    </select>

    <button>Отправить</button>
  </form>

$(document).ready(function() {

  $("#form").submit(function() {
    $.ajax({
      type: "POST",
      url: "mail.php",
      data: $(this).serialize()
    }).done(function() {
      $(this).find("input").val("");  // вот здесьь нужно еще что-то добавлять ? 
      alert("Спасибо за заявку! Скоро мы с вами свяжемся.");
      $("#form").trigger("reset");
    });
    return false;
  });

});

<?php

$recepient = "[email protected]";
$sitename = "Название сайта";

$name = trim($_POST["name"]);
$phone = trim($_POST["phone"]);
$text = trim($_POST["text"]);
$select = trim($_POST[]); // что вписывать сюда ?
$message = "Имя: $name \nТелефон: $phone \nТекст: $text \nВыбор: $select";

$pagetitle = "Новая заявка с сайта \"$sitename\"";
mail($recepient, $pagetitle, $message, "Content-type: text/plain; charset=\"utf-8\"\n From: $recepient");

There are a couple of comments. In general, what needs to be tweaked to everything else so that, in addition to the inputs, the selected one in the select form is sent?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sunrails, 2015-11-28
@Fargal_1

<select name="select_value">
      <option value="0">Ващ выбор</option>
      <option value="1">Выбор 1</option>
      <option value="2">Выбор 2</option>
</select>

PS consider sanitizing the input.

D
Dmitry Kovalsky, 2015-11-28
@dmitryKovalskiy

Add select to at least some value of the name attribute and substitute it in $_POST[]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question