End User web form that feeds CMS record?

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

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?

By dougdrury - October 12, 2010

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?

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

By Jason - October 12, 2010

Hi,

Yes, that should work. Let me know how it goes.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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