HomeMySQL Page 4 - Building a Simple ColdFusion Content Management System with MySQL
Add/Modify Form - MySQL
This tutorial lays out the basics for creating a content management system in ColdFusion and MySQL. The System leverages hierarchical data to automatically build breadcrumb lists, a side navigation menu, as well as a site map. The goal of this tutorial is to provide a framework upon which to build a content management system that is easy to customize and maintain, leaving the web author more time to create content than maintain code.
We are now going to look at the add and modify process of this application. When you click on either the Modify or Add link it will take you to the first part of the CFIF statement. I am just going to state once for the record that these forms were intentionally left very plain. I was going for function, you can make it look nice when you integrate it into your site.
Now I will walk through the above code. The first CFIF statement (line 1) sets a url.id to either 0 for a new record, or a value that was passed in the "url.mod". What this does for you is if you are modifying a page, it will show the information in the form, if you are adding a page the form will be blank.
The CFQUERY queries out the record if you are modifying. Set the form's ACTION to the same page you are working on. Lines 8 through 14 place the form fields on the page and populate them with values if you are modifying the record. Lines 16 through 23 test to see what you are trying to and sends you to the appropriate action. If you are trying to modify an existing document the submit button is named Modify with a value of Modify. If you are trying to add a new document then the submit button is named Add with a value of Add. That way you can put the appropriate action in the section of the page's CFIF statements. All you have to do is see if the form variables are ISDEFINED.