Reputation: 14511
I have a form that posts some data to a PHP processing script. I am also using Google map javascript and would like to pass that form data to the processing script. I have to do this through GET (since javascript is client side) but the form action must be POST for the form data.
Can I encode the form action with javascript variable data to act like a GET for the processing script?
Here's the form action:
<form id="form1" name="form1" method="post" action="catchprocess.php">
How do I pass the javascript data into the catchprocess.php (like a PHP GET method?)
function saveData() {
var name = escape(document.getElementById("name").value);
var address = escape(document.getElementById("address").value);
var type = document.getElementById("type").value;
var latlng = marker.getLatLng();
var lat = latlng.lat();
var lng = latlng.lng();
var url = "phpsqlinfo_addrow.php?name=" + name + "&address=" + address +
"&type=" + type + "&lat=" + lat + "&lng=" + lng;
GDownloadUrl(url, function(data, responseCode) {
if (responseCode == 200 && data.length <= 1) {
marker.closeInfoWindow();
document.getElementById("message").innerHTML = "Location added.";
}
});
}
Upvotes: 0
Views: 545
Reputation: 2021
I am not quite clear what you are attempting to do, but here are some observations that might help.
You don't have to use GET clientside - you are choosing to use GET by using GDownloadURL. If you code your own xmlHttpRequest it can issue POST (or HEAD, PUT, DELETE and OPTIONS). Using xmlhttprequest directly is not hard (Goolge for example).
As you have written it, the data you have in name, address and type will be passed to catchprocess.php. It will appear in $_POST and $_REQUEST.
If you want to add the data you get from marker.getLatLng, simply use javascript to set the value of some hidden fields in the form. Your "submit" button must call a javascript routine to set these values before it calls submit on the form. This will supply the last set of data only.
The gDownloadURL call to phpsqlinfo_addrow.php may have added the data from all the calls to some database (I don't actually know what it does). If so, then you may be able to read all the data from where it has been stored, and get all recorded positions.
Upvotes: 0
Reputation: 10371
@user547794: Just...cheat.
<form id="form1" name="form1" method="post" action="catchprocess.php?action=whatever">
You can send POST
and GET
data this way. :-)
Upvotes: 1