在选择特定div时发布特定数据

时间:2015-05-19 07:32:00

标签: javascript php

如果选择了下拉列表中的特定字段,如何将数据发送到我的电子邮件?我有两个下拉列表,第一个工作,我收到电子邮件中的数据,但我没有得到第二个数据。

<script type="text/javascript">
    function showfield(name){
    if(name=='Spa')
          document.getElementById('div1').style.display="block";
    else 
         document.getElementById('div1').style.display="none";
    if(name=='Masaj')
        document.getElementById('div2').style.display="block";
    else 
        document.getElementById('div2').style.display="none";
    if(name=='Impachetari')
         document.getElementById('div3').style.display="block";
    else 
         document.getElementById('div3').style.display="none";
    }
    </script>

<select name="options" id="options" onchange="showfield(this.options[this.selectedIndex].value)">       
            <option value="Spa">Spa</option>
            <option value="Masaj">Masaj</option>
            <option value="Impachetari">Impachetari</option>
            <option value="Pat sare salina">Pat sare salina</option>
            <option value="E-fitness"> E-Fitness</option>
        </select>

        <div id="div1" style="display: none;">Optiuni Spa: 
            <select name="div1">
                <option value="tubapasarata">Tuburi cu apa sarata</option>
                <option value="tubexterior">Tub Exterior</option>
                <option value="jacuzzi">Jacuzzi</option>
                <option value="sauna uscata">Sauna Uscata</option>
                <option value="sauna umeda">Sauna Umeda</option>
                <option value="salina">Salina</option>
            </select>
        </div>

2 个答案:

答案 0 :(得分:0)

<?php

if(isset($_POST['email'])) {

    $email_to = "example@example.com";
    $email_subject = "Despre Example";


function died($error) {
    echo "Ne pare rau dar a intervenit o eroare. <br>";
    echo "Aceste erori pot fi regasite mai jos : <br> </br>";
    echo "$error <br> </br>";
    echo "Va rugam sa va intoarceti la pagina anterioara si sa reparati aceste erori.";
    die ();
}

if(!isset($_POST['first_name']) ||
    !isset($_POST['email']) ||
    !isset($_POST['subject']) ||
    !isset($_POST['comments']) ||
    !isset($_POST['date']) ||
    !isset($_POST['hour'])) {

        died("Ne cerem scuze,dar au aparut niste probleme cu formularul pe care l-ati trimis.");
    }


$first_name = $_POST['first_name'];
$email_from = $_POST['email'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
$date = $_POST['date'];
$options = $_POST['options'];
$hour = $_POST['hour'];
$antibot = $_POST['antibot'];

$error_message = "";

$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'Adresa de email este invalida. <br>';
}
$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'Numele este invalid.';
}

if(strlen($subject) < 3) {
    $error_message .= '* Subiectul scris nu este unul valid.';
}

if(strlen($comments) < 2) {
    $error_message .= 'Mesajul scris nu este unul valid.';
}

if(strlen($date) < 2) {
    $error_message .= 'Va rugam sa selectati o data completa. Ex: Zi / luna / an.';
}

if(strlen($hour) < 2) {
    $error_message .= 'Va rugam sa alegeti o ora completa. Ex: 14:00.';
}

if(strlen($antibot) > 0 ) {
    $error_message .= 'We don`t like spammers.';
}

if(strlen($error_message) > 0) {
    died($error_message);
  }

 $email_message = "Detaliile formularului mai jos.\n\n";

  function clean_string($string) {

      $bad = array("content-type","bcc:","to:","cc:","href");

      return str_replace($bad,"",$string);

    }

$email_message .= "Nume: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Subiect: ".clean_string($subject)."\n";
$email_message .= "Mesaj: ".clean_string($comments)."\n";
$email_message .= "Data: ".clean_string($date)."\n";
$email_message .= "Ora: ".clean_string($hour)."\n";
$email_message .= "Optiuni: ".clean_string($options)."\n";

// Email Header

$headers = 'From: '.$email_from."\r\n".

'Reply-To: '.$email_from."\r\n" .

'X-Mailer: PHP/' . phpversion();

@mail($email_to, $email_subject, $email_message, $headers);  


?>
<!-- include your own success html here -->

Multumim pentru mesaj. Vom raspunde cat de curand posibil.

<?php

}

答案 1 :(得分:0)

据我了解,您需要这样的解决方案。你想像在javacript函数中那样做。它在php中为选定的选项获取特定服务也是如此。

myMenu.setMainPage(...);