Getting data to our edit page
The current page looks similar to the page where we put the form. To get the data from our database onto the page, we need to do a few things here. First, let us change the action of the form tag to product_edit.cfm
. We can modify the processing section of the page first, which will make things simpler. Add the following code to your product_edit.cfm
page:
<!--- Processing ---> <cfparam name="url.id" default="0"> <cfscript> objProduct = createObject("component","product").init(dsn="cfb"); objProduct.load(url.id); </cfscript>
We need the default value set so that we do not receive an error message if the page is called without an id
. After we set our default, we will see that we have created an object from our CFC object class. This time, we are passing the Data Source Name
dsn
into the object through the constructor method. This makes our code more portable, and ready for reuse. Once we have an instance, we set the current record using...