0

I keep getting "Undefined index: latitude" and "Undefined index: longitude"

I was trying to make it work for hours, but i am not able to :( Would you please help me? I need those two forms seperated each other.How can i link them together? Thanks in advance :)

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title</title>
</head>
<script>
var x=document.getElementById("log");
function getLocation()
  {
  if (navigator.geolocation)
    {
    navigator.geolocation.getCurrentPosition(showPosition);
    }
  else{x.innerHTML="GPS szolgáltatás nem müködik ezen a böngészőn, kérlek értesítsd a     rendszergazdát!";}
  }
function showPosition(position)
  {
     var latitude = position.coords.latitude;
     var longitude = position.coords.longitude;
     document.getElementById("longitude").value = longitude;
     document.getElementById("latitude").value = latitude;
  }
</script>
<p id="log">
    <form method="post">
    <input type="hidden" name= "longitude" id="longitude">
    <input type= "hidden" name ="latitude" id="latitude">
    </form>
</p>
    <br>
    <br>
    <form action="" method="post">
    <input type="submit" name="ido" value="Click" /></td>
    </form>

<?php
    if(isset($_POST["ido"])) {
    echo "<script>getLocation();</script>";
        $latitude=$_POST["latitude"];
        $longitude=$_POST["longitude"];
    print_r($_POST);
        }
?>
</html>
4

2 回答 2

1

那是因为您form不包含元素latitudeand longitude,而您定义的上述表单具有这些字段,但它们从未提交。

<form action="" method="post">
    <input type="hidden" name= "longitude" id="longitude"> <!-- I have added here-->
    <input type= "hidden" name ="latitude" id="latitude"> <!-- I have added here-->
    <input type="submit" name="ido" value="Click" /></td>
    </form>
于 2013-10-25T10:22:12.740 回答
0

如果您需要独立的表单 - 那么您应该考虑使用自定义提交方法并通过 ajax 提交。这将使您有机会解析所需的元素,然后提交数据。

于 2013-10-25T11:54:45.113 回答