On Jun 14, 2005, at 6:04 PM, Mark wrote:
The first type of CFC I would like to write is ones that deal with forms -
and there queries.

Not sure what you're really looking for here. What exactly do you want to do with the forms?


I think most developers using CFCs still have forms posted back to regular CFM pages and those pages manipulate CFCs to create an object containing the relevant form data, validate it and store it back to the database (if that's what your app does).

I've looked into that MachII thing and it looks really complicated... can
anyone help me?

Mach II isn't complicated but it does rely on some OO principles that can be a bit overwhelming if you're new to OO! Here's how Mach II typically handles a form:


- User fills in form and clicks submit.
- Form posts to index.cfm / Mach II which creates an object (event) containing all of the form field data.
- The event handler typically makes a bean out of certain form fields (a simple CFC to encapsulate the data).
- The event handler usually runs a filter to validate the data (essentially just calling the validate() method on the bean CFC).
- If the data is valid, the event handler usually tells a listener (CFC) to store the data - usually by passing the bean CFC to a Data Access Object CFC which contains the SQL.
- If the data is invalid, a new event is usually raised to cause the form to redisplay with errors indicated.


You could do most of the above in a simple CFM page without Mach II for now:

        <cfset myFormObj = createObject("component","MyFormObj").init(form) />
        <cfif myFormObj.validate()>
                <cfinvoke component="FormObjDAO" method="create" data="#myFormObj# />
        <cfelse>
                <!--- redisplay form with errors --->
        </cfif>

That assumes several things:
1. MyFormObj.cfc exists to encapsulate the form data
2. MyFormObj.cfc provides an init() method taking a struct to initialize the object
3. MyFormObj.cfc provides getXxx() for each data member xxx (used by the DAO below)
4. MyFormObj.cfc has a validate() method that returns boolean (true for valid, false for invalid).
5. FormObjDAO.cfc exists to provide CRUD operations for MyFormObj data.
6. FormObjDAO.cfc has a create() method that inserts data into the database (and takes an argument called 'data' of type 'MyFormObj')
7. FormObjDAO.create() calls the necessary getXxx() methods on the data object it is passed


Hope that helps...

Sean A Corfield -- http://www.corfield.org/blog/

"I have always wished that my computer would be as easy to use as my telephone. My wish has come true - I no longer know how to use my telephone."
-- Bjarne Stroustrup


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.


CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to