【发布时间】:2012-02-14 10:59:33
【问题描述】:
我有一个表单,其中有一些我通过 Jquery(动态)添加的元素,但问题是除了这些变量之外,所有内容都被发布到 PHP 操作文件中。
我想在php文件中获取这些文本框的值。
代码:
Jquery 代码:
var temp = $('#waypoints').val();
var i=1;
var inputButtons = "<b>Stopover:</b><input type='text' class='stopovers' name='stopover"+i+"'><br>";
var length = '<input type="hidden" value="'+temp+'" name="length" />';
inputButtons+= length;
if(temp==0){
$('div#stopovers').html("");
}
else if(temp==1){ //if a single way point
$('div#stopovers').html(inputButtons);
}
else{
while(i<temp){
i++;
inputButtons += "<b>Stopover:</b><input type='text' class='stopovers' name='stopover"+i+"'><br>";
$('div#stopovers').html(inputButtons);
}
}
PHP 代码:
$start = $_POST['start'];
$end = $_POST['end'];
$length= $_POST['length'];
echo $length;
echo "<br><br>".$start;
echo "<br><br>".$end;
//inserting into the 'locations' table
$query = mysql_query("INSERT INTO `locations` (`pid`, `location`, `type`) VALUES ('$package_id', '$start', 'start');");
$query = mysql_query("INSERT INTO `locations` (`pid`, `location`, `type`) VALUES ('$package_id', '$end', 'destination');");
$j=0;
for($i=1; $i<=$length; $i++){
$stopover='stopover'.$i;
$stopovers[j]=$_POST[$stopover];
//echo 'stopover'.$i;
$query = mysql_query("INSERT INTO `blankand_pts`.`locations` (`pid`, `location`, `type`) VALUES ('$package_id', '$stopovers[j]', 'stopover') ");
echo "<br><br>blah: ".$stopovers[j];
$j++;
}
HTML/表单代码:
<b>Starting city:</b>
<input type="text" id="start" name="start"><div class="undertext">Format: New Delhi, India</div>
<b>Number of stop overs:</b>
<select id="waypoints">
<option selected="selected">Select</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select><br>
<div id="stopovers">
</div><br>
<b>Destination:</b>
<input type="text" id="end" name="end"><div class="undertext">Format: New Delhi, India</div>
<br />
注意:当我设置手动值时,查询工作得非常好
【问题讨论】:
-
您需要添加更多来源 - 表格在哪里?添加到表单中的新元素在哪里?
-
表单中有太多与此无关的元素,它们工作正常,我觉得问题出在某个地方。但是,如果你愿意,我也会上传表单中的代码?
标签: php javascript jquery forms form-submit