简体   繁体   中英

Undefined index and geotagging script

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>

That is because your form does not contain the elements latitude and longitude , whereas the above form what you have defined has those fields , but they are never submitted.

<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>

If you need the forms to be independent - then you should consider using a custom submit method and submit via ajax. That will give you the opportunity to parse the elements you need and then submit the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM