We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4968
    • 3 Posts
    I am trying to build an admin form that will allow the administrator to add, insert and delete data from an external mySQL database. It will be a basic web form with all the usual input, select, radio buttons etc..

    I am pretty new to PHP and Modx so I am not sure if I am going down the correct path. So far I have managed to connect to the external database within MAMP using the dbapi. I can retrieve info from the external db to publish, so once I work out how to make an interface that is easy to use and specifically add data I think I am there.

    Does anyone know of an example that shows how this is done with a standard web form, showing how the calls are made to add the info inserted by the administrator to the database. Is there a specific modx api call I can use , or do I need to set up a snippet of some sort.

    Cheers
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Is this a module for the Manager, or a snippet for using in the front-end?
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 4968
        • 3 Posts
        Hi

        This is for use on the front-end as eventually I would like the users to enter info that populates the database.

        Cheers
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          If your info is in a table in the same database as your MODx tables, you can access it in the same way any of the many snippets that access the database do.

          For example, MaxiGallery’s maxigallery.class.php file has a number of functions to access the database, WebLoginPE’s webloginpe.class.php file also. Another good example for study might be the FileDownload’s data.db.class.inc.php file, although it is not commented as well.

          If you want to get fancy with some AJAX, I’ve got a three-part article on creating a paging, sortable, searchable data grid using extjs library. It’s simply a matter of adding a couple of parameters to a javascript function to make it editable as well, although that would require a bit more processing code in the backend .php file, of course. I’ve got another set of articles on creating an editable grid as well as a .csv upload and data insertion module for the Manager using the prototype library which might also be of use.

          http://www.sottwell.com/article-extjs1.html
          http://www.sottwell.com/database-module-3.html
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 4968
            • 3 Posts
            Thanks for the info. I will have a play with the links you provided.