End User web form that feeds CMS record?

4 posts by 2 authors in: Forums > CMS Builder
Last Post: October 12, 2010   (RSS)

I have a need to gather some text and a file upload from a webform on the presentation layer of the site (not in the CMS) that feeds into a CMS table. I can create the form via HTML, and know PHP to get the document and POST info, but I am lost on how to nicely push it into the CMS data tables. I can look at the SQL tables and hack it by inserting into the CMS table and then referencing it in the cms_uploads table with a new insert using that record num, but was wondering if anyone else has had this request and you all had come up with a more elegant solution.

Thanks,
Doug

Re: [dougdrury] End User web form that feeds CMS record?

By Jason - October 12, 2010

Hi Doug,

To get information into the CMS from an HTML form, you'll need to insert a record directly into MySQL database. This is pretty straight forward though. If you have your line requiring viewer_functions.php:
example:
<?php require_once("cmsAdmin/lib/viewer_functions.php");?>

you wont have to worry about any database connections, the script will take care of those for you.

If you take a look at your section in the section editor, you'll be able to see the names of all of the fields in that table. It's then just a matter of writing the INSERT statement.

Here's an example to help get you started:

<?php
$query = "INSERT INTO `{$TABLE_PREFIX}SECTIONNAME` SET
createdDate = NOW(),
updatedDate = NOW(),
createdByUserNum = 0,
updatedByUserNum = 0,
dragSortOrder = 0,

title = '".mysql_escape(@$_REQUEST['title'])."'";


mysql_query($query) or die("MySQL Error:".mysql_error()."<br/>\n");
?>


You would just keep filling fields just like "title" until you've filled all the fields you need.
You'll also replace "SECTIONNAME" with the name of your table. The variable $TABLE_PREFIX is a global variable that stores the table prefix you decided on when you installed CMS Builder (ex: "cms_"). So if your table name is cms_news, you would use `{$TABLE_PREFIX}news`. This is good if you ever have to change your table prefix, your script will still work.

The line:
mysql_query($query) or die("MySQL Error:".mysql_error()."<br/>\n");
submits the query to the database. If successful, you'll be able to see the record displayed in CMS Builder.

Hope this gets you started. Let me know if you have any questions.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] End User web form that feeds CMS record?

Jason,
Thanks for that. That makes sense. As for assigning an upload to that record, can I just use the mysql_insert_id() call to get the record number and then create an entry in the uploads table that points to the file that got uploaded via the web form?