We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1512
    • 57 Posts
    Hi there,

    I’ve successfully got the MODx API sending data to an external database when someone submits a form, but what i’m looking to do is the following:

    On an External PHP Site (not MODx)
    - member logs in, updates info (same fields as in modx)
    - admin then presses a button (SYNC TO MODx)

    then the external non-modx php script (has a field called modx_page_id so it knows what page id to update) gets sent into modx and matches the fields to those for that specific page id and updates them.

    Anyone done any work like this before or have any idea where i can start?

    thanks
    André
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      Those are complex interactions you’re talking about. You’d have to clarify this in a lot more detail before I can make any meaningful comments.

      When you say the non-MODx site has the "same fields", what do you mean, exactly? Does the other site store data in a database that has the same structure as those used by MODx included relational tables for any template variables for a page, or since you mentioned members logging in, are you referring to the tables that store data for a member?

      And how do you expect to update the MODx database remotely? It’s unlikely (and insecure) to open up your database for manipulation by an outside host. You’d have to set that up inside of MySQL, e.g. by adding a new user at that host:
      CREATE USER 'foreign_user'@'123.123.123.123' IDENTIFIED BY 'some password';


      And give that user access to the same tables... but... yuck... this just seems like a cluster@$#% waiting to happen.

      Maybe you should back up and describe a bit more broadly what you’re trying to accomplish.
        • 32674
        • 101 Posts
        I haven’t done anything like this, but I think it would be a great 3PC, or extended snippet of some sort, to allow adding/editing of content to Modx remotely. (caveat: Im thinking revo here for my example, as Ive never used evo or have a clue how to do it there.)

        I’d probably attempt to approach it so that:

        When the ’sync’ button is pushed on your site external to modx -- curl, maybe thru through ajax, would login to your modx backend manager account (or any specific author/content editor’s backend account) so you then have permissions to create/update content. Then run a script that grabs the modx object through the API: modx object ----> the modresource object -----> ’set’ & ’setcontent’ methods. Then and use those methods to create/update your modx resources from the external php site.

        Basically you’d be reusing the modx API again to control adding new (or sync’ing existing) content in the other direction. API docs here: http://api.modxcms.com/ . Im sure there ’gottcha’s’ as far as permissions go, but someone here has certainly added external content into modx programmatically, and can detail that part of the process.