Thursday, June 16, 2011

Copying ProForms Data to Custom Tables

This is a follow-up on my previous post, where I was trying to figure out how to maintain separation between the Joomla database tables that handle the UI of the website and the custom database tables that handle the actual Talking Owl AI logic and application.

I found a fantastic solution that works well.

To begin with, my Joomla installation is Joomla! 1.6.3 with two installed extensions:

    PHP Module (Fiji Web Design), which allows me to enter any custom PHP into a module box that I want. (Similar to the custom HTML module, but allows you to use PHP)

    ProForms (Mad4Media), which allows you to design custom input forms, do input validation and Captcha control, and store the data entered into Joomla Extension database tables handled by ProForms.

My challenge is: I want to use the ProForms functionality to allow users to enter in the information for creating a new Talking Owl on the site, but I want the data for the owl to end up in a separate set of custom tables that are handled by my own Talking Owl application and not ProForms or Joomla.

These are the steps I took:

  1. Create a Joomla article called "Your new Talking Owl has hatched!" with minimal content. (Something like "Congratulations!")
  2. Create a PHP module that is only rendered when that one page is displayed.
  3. In the custom PHP for that module, use the Joomla database object to query the database and retrieve all of the form information concerning the most recent talking owl (just added) created by the current logged in user. Once you have that data, use an INSERT statement to copy that information into a new row in the custom Talking Owl table. Finally, have the PHP module write as output to the page a javascript re-direct (<script>location.href= ...etc..</script>) that re-directs the browser to the page for the owl that was just created.
  4. In the ProForms area of the administration section of the site, change the ProForms settings so that after the form is submitted, it re-directs the user to the "Your new Talking Owl has hatched!" page.

The end result of all of this is the when the user submits the form, the form itself will save the data in the ProForms tables, the system will briefly re-direct the user to the "Congratulations" page, at which time the system will copy this data into your own custom tables, after which the user will be re-directed to the main page of the owl that was just created.

No comments:

Post a Comment