0
我试图插入/提交表单数据到XML,但它没有保存任何东西到XML文件中..目前只发送Latitude行来让它工作。XML的地理空间
我一直在关闭GitHub Geocomplete表单脚本并尝试将发送数据添加到XML脚本,但我看不到什么是缺少的?
的index.php
<!DOCTYPE html>
<html>
<head>
<title>$.geocomplete()</title>
<meta charset="UTF-8">
<style type="text/css" media="screen">
form { width: 300px; float: left; }
fieldset { width: 320px; margin-top: 20px}
fieldset strong { display: block; margin: 0.5em 0 0em; }
fieldset input { width: 95%; }
ul span { color: #999; }
</style>
</head>
<body>
<?php
$xmldoc = new DOMDocument();
$xmldoc->load('sample.xml', LIBXML_NOBLANKS);
$latitude = $xmldoc->firstChild->firstChild;
if($latitude!=null){
while($latitude!=null){
echo $latitude->textContent.'<br/>';
$latitude = $latitude->nextSibling;
}
}
?>
<div class="map_canvas"></div>
<form name='input' action='insert.php' method='post'>
<input id="geocomplete" type="text" placeholder="Type in an address" value="Empire State Bldg" />
<input id="find" type="button" value="find" />
<fieldset>
<h3>Address-Details</h3>
<label>Latitude</label>
<input name="latitude" type="text" value="">
<label>Longitude</label>
<input name="lng" type="text" value="">
<label>Formatted Address</label>
<input name="formatted_address" type="text" value="">
<label>Locality</label>
<input name="locality" type="text" value="">
</fieldset>
<input type='submit' value='send'/>
</form>
<script src="http://maps.googleapis.com/maps/api/js?key=API KEY sensor=false&libraries=places"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="findlocation/jquery.geocomplete.js"></script>
<script>
$(function(){
$("#geocomplete").geocomplete({
map: ".map_canvas",
details: "form",
types: ["geocode", "establishment"],
});
$("#find").click(function(){
$("#geocomplete").trigger("geocode");
});
});
</script>
</body>
</html>
INSERT.PHP
<?php
header('Location:index.php');
$xmldoc = new DOMDocument();
$xmldoc->load('sample.xml');
$newAct = $_POST['latitude'];
$root = $xmldoc->firstChild;
$newElement = $xmldoc->createElement('latitude');
$root->appendChild($newElement);
$newText = $xmldoc->createTextNode($newAct);
$newElement->appendChild($newText);
$xmldoc->save('sample.xml');
?>
sample.xml中
<list>
<latitude></latitude>
<list>
现在我明白了!谢谢! – Steve