Generally, my forms all connect with a bean. If I have a form field for
email, my bean has a getEmail() method on it.
Then, when I submit my form, I use event.makeEventBean( FormBean ,
"list,of,form,fields,to,shove,in,the,bean") to populate the bean with the
values from the event.
Once I validate, and find errors, I simply add a result that goes back to
the form.
The form once again only talks to the bean, but this time, the bean has the
parameters from the event (what the user typed into the form).
<cffunction name="doSendMessage" access="public" returnType="void"
output="false">
<cfargument name="event" type="any">
<cfset var UserMsg = arguments.event.getValue("UserMsg") />
<!--- populate the bean with the submitted form values --->
<cfset var messageBean = arguments.event.makeEventBean( "MessageBean",
"ActivityID,ChallengeID,InvitationID,MemberID,Message,ReplyToMessageID,TeamID")
/>
<cfset var resultToAdd = "failure" />
<!--- validate and save if the bean is quality --->
<cfif messageBean.validate() IS true>
<cfset beans.messageHandler.save( messageBean ) />
<cfset resultToAdd = "success" />
<cfif setSuccessMessage IS true>
<cfset UserMsg.addSuccess( "You sent: #messageBean.getMessage()#" ) />
</cfif>
</cfif>
<!--- add the appropriate result --->
<cfset arguments.event.addResult( resultToAdd ) />
</cffunction>
Thus completes the circle.
DW
On Wed, Jan 19, 2011 at 1:02 PM, Jim Priest <[email protected]> wrote:
> I'm trying to go back and clean up some of the things I glossed over during
> initial development of my first MG application. :)
>
> Question:
> How do you, on a validation error, go back to the form and populate the
> fields?
>
> I'm digging through the MG list, and some of Bob's ValidateThis examples
> and am stuck.
>
> I have my UserRecord when the form initially loads, and on validation
> failure I seem to be able to pull the form values out of the event if there
> is an error but it seems like I'll have to add a lot of logic to my form to:
>
> a) check if the form was submitted
> b) if there is a validation error pull from event, else pull from
> UserRecord...
>
> I'm wondering if there is a relatively simple way to do this that I'm
> overlooking...
>
> I'm using CF ORM and I imagine I have a detached object floating around
> populated with this data... is there someway for me to grab that?
>
> Thanks!
> Jim
>
> --
> Model-Glue Sites:
> Home Page: http://www.model-glue.com
> Documentation: http://docs.model-glue.com
> Bug Tracker: http://bugs.model-glue.com
> Blog: http://www.model-glue.com/blog
>
> You received this message because you are subscribed to the Google
> Groups "model-glue" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<model-glue%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/model-glue?hl=en
--
Plutarch - "The mind is not a vessel to be filled but a fire to be kindled."
--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en