Hi Rubble,
So assuming you have your points in a text area, something like this:
<textarea id="points">
208,221,208,202,198,199,201,191,218,176,229,155,221,132,196,117,169,131,157,158,163,172,177,164,173,180,190,185,192,199,187,201,185,222
</textarea>
Then what you need is a button on the page, which when clicked fires an AJAX request to your PHP script.
For AJAX stuff I always use jQuery, as the syntax is concise and it does a lot of the heavy lifting for you.
Our button, with an on click event handler:
<button id="createFile">Create text file</button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$("#createFile").on("click", function(){
// Code here will be executed when button clicked
});
</script>
Now when clicked we need to grab the contents of the text area and submit this to the PHP script:
$("#createFile").on("click", function(){
$.ajax({
type: "POST",
url: "points.php",
data: {"points": $("#points").text()},
success: function(response){
console.log(response);
}
});
});
The success callback will log the server’s response to the console and although not strictly necessary, will give us an indication at o whether this has worked.
This gives us:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
</style>
</head>
<body>
<textarea id="points">
208,221,208,202,198,199,201,191,218,176,229,155,221,132,196,117,169,131,157,158,163,172,177,164,173,180,190,185,192,199,187,201,185,222
</textarea>
<button id="createFile">Create text file</button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$("#createFile").on("click", function(){
$.ajax({
type: "POST",
url: "points.php",
data: {"points": $("#points").text()},
success: function(response){
console.log(response);
}
});
});
</script>
</body>
</html>
points.php
<?php
$points = $_POST["points"];
print_r($points);
In your example, you will then be able to extract the user generated coordinates from $_POST["points"]
and create your text file.
If you have any questions, just let us know.