使用 $_GET 回显输入值属性

Use $_GET to echo input value attribute

我有这个 html/javascript 脚本。每次用户单击地图时,它都会打开一个表单。同时,它将坐标发送到输入标签。

htmlFile.html

    <div id="sidebar" class="sidebar">
        <form action="data.php" method="get">
            <input id="lat" type="hidden" value="">
            <input id="long" type="hidden" value="">
            <input id="name" type="text" name="name">
            <input id="surname" type="text" name="surname">
            <input type="submit" value="Submit">
        </form>
     </div>

     map.on('click', addMarker);
            function addMarker(e){
                // Add marker to map at click location; add popup window
                var newMarker = new L.marker(e.latlng).addTo(map);
                sidebar.show();
                document.getElementById("lat").value = e.latlng.lat;
                document.getElementById("long").value = e.latlng.lng;
                console.log(e.latlng.lat);
                console.log(e.latlng.lng);
            } 

我希望能够回显“纬度”和“经度”值。

这是我的 PHP 脚本: data.php

$name = $_GET['name'];
$surname = $_GET['surname'];
echo $surname;
$lat = $_GET["lat"]; # This is were I have a problem
echo $lat; 

这段代码需要添加name属性<input id="lat" type="hidden" value=""> :)