2014-07-26 83 views
0

所以我有一个表格,它应该发布国家选定的国家和任何一个国家或城市从任何下拉菜单,它只是张贴在国家下的两个选择,尽管这些名称不同在PHP邮件程序脚本中的表单和发布数据中。POST数据动态选择不发送

所以这里是形式:

<select style="width: 64%;" name="country" class="country"> 
    <option value="UK">UK</option> 
    <option value="US">US</option> 
</select> 


<select style="width: 64%;" class='city' name="city"> 

</select></center> 

这里是JS:

var ukCities = ['Avon', 'Bedfordshire', 'Berkshire']; 
var usCities = ['Alabama', 'Alaska', 'Arizona']; 

$(document).on("change", "select.country", function() { 
    var country = $("select.country").val(); 
    var cities; 
    if(country === 'UK'){ 
     cities = ukCities; 
    } 
    else{ 
     cities = usCities; 
    } 
    $("select.city").empty(); 
    $.each(cities, function(index, element){ 
      $("select.city").append($("<option></option>").attr("value", country).text(element)); 
    }); 
}); 
$("select.country").val('UK').trigger('change'); 

在这里,这些都是应该被张贴的形式PHP mialer脚本是什么:

$mail->Body = 
'Name: ' . $_POST["assocName"] . 
'<br>Email: ' . $_POST["firstName"] . 
'<br>Tel: ' . $_POST["lastName"] . 
'<br>Position: ' . $_POST["position"] . 
'<br>Country: ' . $_POST["country"] . 
'<br>City: ' . $_POST["city"] . 
'<br>Community Type: ' . $_POST["comType"] . 
'<br>Dwellings: ' . $_POST["dwellings"] . 
'<br>Email: ' . $_POST["emailAddress"]; 

例如,当我选择英国和一个城市时,电子邮件通过给我提供城市和国家的城市。

+1

你容易受到XSS –

+0

你是什么意思“给我这个城市的国家和城市”?你在哪里调用PHP文件? – Shahar

+0

我只给了你造成我一个问题的部分表单。我们收到电子邮件,问题是,如果我选择英国,然后选择贝德福德郡,并提交表格,我收到的电子邮件就会显示我向英国国家和城市回复了 – user3520443

回答

1

它给你的城市,因为这两个国家与城市:

$("select.city").append($("<option></option>").attr("value", country).text(element)); 

您需要设置valueelement而不是country,所以它读取:

$("select.city").append($("<option></option>").attr("value", element).text(element)); 

HTML不甚至可以看到option标签之间有什么,只有它们的value是。这就是发布的内容