I have a form to associate some text to a marker on a Leaflet map:
<form action="map.php" method="POST">
<section>
<label>write some text here</label>
<textarea id="text" rows="3" name="area"></textarea>
</section>
<input type="submit" value="show map" />
</form>
As you can see above, the content of the textarea is passed to the page map.php, where a map is shown.
On the map, the place marker is shown, and a popup contains the text posted through the textarea (variable $text
):
<?php
$text = htmlspecialchars($_POST["text"]);
?>
<center>
<div id="map" class="embed-container"></div>
</center>
<script>
var map = L.map('map').setView([46.13, 11.11], 9);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
maxZoom: 17,
minZoom: 9
}).addTo(map);
</script>
<script>
var icon = L.icon({
iconUrl: 'img/gps.png',
iconSize: [25, 25],
});
var marker = L.marker(['<?=$latitude;?>', '<?=$longitude;?>'], {icon: icon}).addTo(map);
marker.bindPopup('<?=$text;?>');
</script>
The problem is that if I press ENTER while I write something in the textarea, nothing is passed to the popup marker. I tried with and such, but nothing works. They are shown in the popup text as strings, not as newlines.
Any ideas?