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>

2 Answers2

1

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>
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
0

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.

BillyBigPotatoes
  • 1,330
  • 11
  • 23