Re: [cfwheels] validate functions

45 views
Skip to first unread message

joshua clingenpeel

unread,
Jul 23, 2010, 5:43:24 PM7/23/10
to cfwh...@googlegroups.com
Sounds like you need to read this chapter:

http://cfwheels.org/docs/chapter/object-validation

:)

On Fri, Jul 23, 2010 at 2:25 PM, Randy Johnson <ra...@cfconcepts.com> wrote:
> Hello,
> I have a question about object validation.
> I have an order form where I want to do form validation, but I need to do
> the validation before I actually go save the item to the database.
> Is there a way for me to use the validate functions to do this or do I need
> to just create my own function in the model to do the initial validation?
> Here is what I have in the controller:
> <cfset order = model("order").new(params.order)>
> <cfset order.checkrequired()>
> check required is my model function where I plan on doing my validation and
> then adding my object errors  so I can use my errormessagesfor() function in
> my view.
> Is this the right way to go about it?
> Thanks!
> Randy
>
> --
> You received this message because you are subscribed to the Google Groups
> "ColdFusion on Wheels" group.
> To post to this group, send email to cfwh...@googlegroups.com.
> To unsubscribe from this group, send email to
> cfwheels+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/cfwheels?hl=en.
>

--
Josh

Randy Johnson

unread,
Jul 23, 2010, 5:53:04 PM7/23/10
to cfwh...@googlegroups.com
I have read it numerous times.   What I am trying to determine is how to do validation without having to do an .save()

I have a form that I need to validate all the fields and then do credit card  processing, only if credit card processing is successful would I actually do the save to the database.

What I want to accomplish is to not have two separate functions for validation.

Could I actually do this in the controller?  order.init();  to run the validation? hmm...  I will have to try that.

Randy

tpet...@gmail.com

unread,
Jul 23, 2010, 6:09:21 PM7/23/10
to ColdFusion on Wheels
sounds like what you want to do is call valid() on the model. that
will return a boolean value telling you if there are any errors:

<cfif payment.valid()>
<!--- do your save here --->
<cfset payment.save()>
<cfelse>
<!--- render your addedit page or credit card form --->
<cfset renderPage("addedit")>
</cfif>



On Jul 23, 5:53 pm, Randy Johnson <ra...@cfconcepts.com> wrote:
> I have read it numerous times.   What I am trying to determine is how to do
> validation without having to do an .save()
>
> I have a form that I need to validate all the fields and then do credit card
>  processing, only if credit card processing is successful would I actually
> do the save to the database.
>
> What I want to accomplish is to not have two separate functions for
> validation.
>
> Could I actually do this in the controller?  order.init();  to run the
> validation? hmm...  I will have to try that.
>
> Randy
>
> On Fri, Jul 23, 2010 at 5:43 PM, joshua clingenpeel <
>
> > > cfwheels+u...@googlegroups.com<cfwheels%2Bunsu...@googlegroups.com>
> > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/cfwheels?hl=en.
>
> > --
> > Josh
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "ColdFusion on Wheels" group.
> > To post to this group, send email to cfwh...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > cfwheels+u...@googlegroups.com<cfwheels%2Bunsu...@googlegroups.com>
> > .

joshua clingenpeel

unread,
Jul 23, 2010, 8:31:28 PM7/23/10
to cfwh...@googlegroups.com
Randy, sorry, didn't mean to insult - Tony has the right of it, and
given your sample code I thought you might not have seen that in the
linked chapter. .valid() is the method you want, it runs all the
validations that you'd normally get on a .save() method before it went
to the database. You get it for free, and it provides a lot more
useful data, so there's no reason to write a custom method to run your
validation suite.

> To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.

tpet...@gmail.com

unread,
Jul 24, 2010, 9:49:57 AM7/24/10
to ColdFusion on Wheels
@randy,

also remember that you are always welcomed to post the actual code or
sudo code to the group. as a matter of fact we encourage it. not only
does it help us to see what the issue is so we can help you better, it
helps everyone here learn and it's great reference for others whenever
they might run into this problem.

that said, if you would like to post your controller and model code
here (or what you can), i'm sure everyone here would be more than
willing to look it over and offer further advice. who knows we might
find an easier solution to your problem.

On Jul 23, 5:53 pm, Randy Johnson <ra...@cfconcepts.com> wrote:
> I have read it numerous times.   What I am trying to determine is how to do
> validation without having to do an .save()
>
> I have a form that I need to validate all the fields and then do credit card
>  processing, only if credit card processing is successful would I actually
> do the save to the database.
>
> What I want to accomplish is to not have two separate functions for
> validation.
>
> Could I actually do this in the controller?  order.init();  to run the
> validation? hmm...  I will have to try that.
>
> Randy
>
> On Fri, Jul 23, 2010 at 5:43 PM, joshua clingenpeel <
>
> > > cfwheels+u...@googlegroups.com<cfwheels%2Bunsu...@googlegroups.com>
> > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/cfwheels?hl=en.
>
> > --
> > Josh
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "ColdFusion on Wheels" group.
> > To post to this group, send email to cfwh...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > cfwheels+u...@googlegroups.com<cfwheels%2Bunsu...@googlegroups.com>
> > .

Randy Johnson

unread,
Jul 24, 2010, 10:37:38 AM7/24/10
to cfwh...@googlegroups.com
No worries Josh...  I wasn't insulted, thank you for your help :-)  I will check.valid today and report back.

Randy

Randy Johnson

unread,
Jul 24, 2010, 10:39:31 AM7/24/10
to cfwh...@googlegroups.com
Tony,

Yep, thanks for the reminder.  If I don't get it worked out today I will sure to report back, but http://cfwheels.org/docs/function/valid  is exactly what I need, not sure how I missed it as many times as I have read the docs.

Randy



To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages