Apologies...long time user, first time API user.
I’m trying to automatically update a TV based on values of other TV’s for a document. I’m using OnBeforeDocFormSave (or should I use OnDocFormSave?) and trying to set the POST var to a value such as:
[tt]$tv1 = $_POST[’tv1’];
$tv2 = $_POST[’tv2’];
$_POST[’autotv’] = $tv1 . ’ - ’ . $tv2;[/tt]
I think I may be missing something. I’m sure this is basic.
Thanks.
Well, I thought if I could set the POST var before saving, it would get written to the database.
I have a site that shows a bunch of properties on a Google Map, using the Google Maps API. The user inputs address, city, zip in TVs. I have code that works using only these fields, but the API has a problem geocoding more than 8-10 addresses on the fly. But if you already have the lat/long it works better I think. So I’m trying to auto populate the lat/long (as a TV) when the user creates the document (ie, the property). So I don’t think placeholders are the answer.
Doesn’t seem to work for me. I tried [tt]$_SERVER[’QUERY_STRING’] .= ’&autotv=’ . $lat . ’,’ . $lng;[/tt]
I could also try using setTemplateVar() but it requires that I know the document id. For existing docs, this is fine, but how can I get the document id for a newly created doc? Could I somehow get this in the OnDocFormSave event? I tried a call with $modx->documentObject[’id’] in this event, but it came up empty.
Any ideas?
Essentially, it includes Google API javascript in your template. Then you make calls to the javascript objects GClientGeocoder, etc. Just another way to do it. But doing it recursively by passing an address fails after 8-10 iterations. So I’m trying to avoid that and just pass the lat/long, but in order to do that, I need to save it at the document in a TV. So the QUERY_STRING, POST, etc I refer to is a request to my server (in the manager) when I save the document.
dev_cw:
No, that was just an example. I’m using 3 TVs (address, city, zip) to pass to the Google Map API, which then returns a latitude/longitude. I will then store the lat/long in the 4th TV.
Well, I abandoned what I thought would be the simple way, and went with doing a DB insert instead. So now I have an automatic geocoder based on address TVs. These can be used to populate a Google Map via the GMap API on your own site. Pretty cool. Let me know if this is code worth seeing and I’ll post the details.