Skip to main content
Inspiring
July 10, 2008
Question

cfcs with forms

  • July 10, 2008
  • 6 replies
  • 619 views
I can't find anywhere about this googling has anyone got a guide to it-or where can i find some info on it? thanks
This topic has been closed for replies.

6 replies

Inspiring
July 11, 2008
Thanks Ian, so if I was to do it the wrong/not commonly used way I would cfparam the arguments and put them into the session not the form values and error check the arguments like this:
<cfif arguments.Name EQ "">
<cfset errors = errors & "where the name half a brain?"></cfif>
and then I would output the session vars in the form actually in the cfc?

So the best way is dan's way then, so I would send the form to another cfm form where I would invoke the cfc-what would I actually do/check/set on the cfc? Thank-you
Inspiring
July 11, 2008
quote:

Originally posted by: Hydrowizard
Thanks Ian, so if I was to do it the wrong/not commonly used way I would cfparam the arguments and put them into the session not the form values and error check the arguments like this:
<cfif arguments.Name EQ "">
<cfset errors = errors & "where the name half a brain?"></cfif>
and then I would output the session vars in the form actually in the cfc?


If you are making your arguments mandatory, you have to send them a value. I'm not sure, but I don't think an empty string will suffice. You probably want to cfparam your form fields before you invoke the cfc.

You didn't ask, but argumentcollection="#form#" is a handy thing to know.
Inspiring
July 11, 2008
You are right Dan an empty string didn't sufice. Anyway it works now thanks
Inspiring
July 11, 2008
Hydrowizard wrote:
> also would the form variables actually now be argument variables instead in the cfc?

Using a CFC as the action of a form is not a commonly used feature. But
it is supported. If you choose to do this, then yes, each form field
becomes an argument of the method called as the form action.
Inspiring
July 11, 2008
also would the form variables actually now be argument variables instead in the cfc?
Inspiring
July 11, 2008
My preferred method is to send a form to another cfm template which accesses the cfc using cfinvoke or CreateObject. If you prefer tags to script, you can use cfobject instead of create object.
Inspiring
July 11, 2008
Thanks Dan that sounds like an interesting way of doing it. For my test I am trying to do it all in the cfc like the code below which works. However, normally I would do this with a simple post and action page and on the action page I would do the following:
create a structure to hold session variables, then do some cfparams to check the form values and assign a default "" to them, clear the session and then put the form values into the session to be able to save what the user put in the form. I do error checking by doing <cfparam name="errors" type="string" default=""> and setting each error message in the cfif blocks.

What do you think of my skeleton code below, I am tempted to do exactly the same in the cfc as I do in my action page but where would I output the session vars to the user in a new form? I would have to do output="true" on the cfc and then that would house the form? I'm not understanding this at the moment! Thanks for helping me out on these concepts.
Inspiring
July 11, 2008
how to do them i know how to send the form to a cfc it is then best practices from there
Inspiring
July 10, 2008
what exactly are you looking for about cfcs and forms?

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/