We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17851
    • 213 Posts
    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.
      Mark Macatee
      President
      Power 10 Solutions
      http://www.power10solutions.com
      • 10449
      • 956 Posts
      try this function mentioned here: http://modxcms.com/forums/index.php/topic,34712.msg210809.html#msg210809

      $_POST is $_POST, and $_GET is $_GET - you’re confusing outside variables with modx variables smiley

      I don’t know what exactly you’re doing, but if you’re only concatenating two TV values, maybe you should better create a placeholder instead?
      $modx->setPlaceholder(’plhName’, ’plhValue’);
        • 17851
        • 213 Posts
        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.
          Mark Macatee
          President
          Power 10 Solutions
          http://www.power10solutions.com
          • 16278
          • 928 Posts
          trying to set the POST var to a value...
          won’t get you far. You can’t set $_POST directly, only through input fields in a FORM element. sad
          You can work your data into the query string of the URL, which the receiving end will see as a $_GET value.
          KP
            • 17851
            • 213 Posts
            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?
              Mark Macatee
              President
              Power 10 Solutions
              http://www.power10solutions.com
              • 16278
              • 928 Posts
              Much the same problem - $_SERVER is a read-only array. The query string is set in the URL, e.g. http://www.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=rg4+8tz&sll=52.947604,-1.130905&sspn=0.093711,0.2211&ie=UTF8&ll=51.482372,-0.958729&spn=0.012107,0.027637&z=15 - all the stuff after the question mark is the query string, which a PHP script can read as $_SERVER[’QUERY_STRING’]. I’m not familiar with the Google Maps API, so I’m not sure how your data fits into this scheme of things. lipsrsealed
              KP
                • 17851
                • 213 Posts
                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.
                  Mark Macatee
                  President
                  Power 10 Solutions
                  http://www.power10solutions.com
                  • 7231
                  • 4,205 Posts
                  What is the output you are recording to the tv? Is this to join several TV values into one? I would keep them isolated and join them programmatically when you need to use it. Otherwise you will have an extra TV that is redundant as far as data is concerned. If you need them in a link:

                  $url = "domain.com/maps?f=[*tv1*]-[*tv2*]";
                  and it will be parsed correctly when the document loads.
                    [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                    Something is happening here, but you don't know what it is.
                    Do you, Mr. Jones? - [bob dylan]
                    • 17851
                    • 213 Posts
                    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.
                      Mark Macatee
                      President
                      Power 10 Solutions
                      http://www.power10solutions.com
                      • 17851
                      • 213 Posts
                      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.
                        Mark Macatee
                        President
                        Power 10 Solutions
                        http://www.power10solutions.com