> For the foreseeable future, validation functions are only available when
> saving to the database.
That's why I was thinking to solve my problem by adjusting myself to
that. Since I think that those validation functions are sent from
heaven :), I really want to keep the functionality. I really want to
use them. In the last project I made in PHP, I was busting my ass to
make sure the validation works as it should, so I really want to use
those functions! :) So my idea now is to save the choir form data in
sections, thus for each section having a DB table on it's own. However
this may not be the best solution, because in this case we we would
have more database tables than we maybe should. But on the other had,
does this really matters? I don't know... My idea was to have
temporary tables that would be used as temporary containers... instead
of using the session scope for that purpose, we could save the
temporary data into temporary tables which would enable to access the
data also after loosing the sessions!
That may sound funny, but I am sure it wouldn't be the first time that
someone makes it this way. However I know that once we will be able to
use NestedProperties(), things won't be so complicated anymore.
So let me explain a little bit more how I was thinking to use those
sections and the "temp" tables.
1. "Main info" section
This section would have only a couple of input fields in the form.
This form would be the first thing that a user would see when clicking
the "Add choir" button in the administration. It would have the
fields: "Choir title" (textfield), "Type of choir" (select), "Date of
the Choir Establishment" (calendar or select), "Number of
singers" (select). This form, or this section would be mainly used for
creating a new record, with a new main record ID in the database. Once
the user would fill up those 4 forms (4 sections) we would just save()
the data into a DB table named "tempchoirs" (I hope this name follows
the Wheels conventions), which would allow us to use both the form
validation functions and the errorMessagesFor() helper function. Now
we would have the ID of the newely inserted choir which we would use
in the following sections (steps of the form) as a foreign key, to
connect the whole choir record (all 4 temp tables).
2. "Address" Section
After saving the data in the first section of the form, we would have
the "tempchoirs" table filled with a new record and we would be
redirected to the second step of the form - to the "Formal info"
section. Actually we would be redirected to a new action, which would
use the same controller. This section would have around 4 or 5 form
fields for the address data (city, house number, post-office
number...) and would save the filled data into the second-section DB
table named "tempadresses".
The procedure would be the same also in the "Formal info" section
(data would be stored in the "tempchoirinformation" DB table) and in
the "Extra infro" section (data would be stored in the
"tempextrachoirinformation" DB table).
Now, here is the important part!
After filling up and checking the data of all 4 sections, the user
would click "Save record" and the information would be moved from the
temporary DB tables to the main tables: "choirs", "addresses",
"choirinformation" and "extrachoirinformation".
The information from the DB tables would move (copy and delete) in
this way:
tempchoirs -> choirs
tempaddresses -> addresses
tempchoirinformation -> choirinformation
tempextrachoirinformation - > extrachoirinformation
Probably you were asking yourself: "What happens after the user stops
on the second step of the form? Do we have only one temp table
filled?"
Yes! Why not? This can also have it's benefits and it certainly
doesn't affect the user at all. Let's say that the user comes back
after a few hours and wants to insert it's choir again from the
beginning (step 1). Once he or she would start filling the form, the
app could suggest names of the choirs that were not finished filling
up and! Maybe by using Ajax.
IMHO this scenario may be useful because in this way we would
certainly keep the functionality of the form validation functions and
the errorMessagesFor() helper function. Also this may be a good idea,
or a good method for some future Wheels versions. Or we could use this
idea to make a new plugin perhaps? Hm... :)
>You can create the tables though and instead of
> calling save(), you can call
> valid()<
http://cfwheels.org/docs/function/valid>to run the validations
> without saving.
Or, instead of everything I wrote above, I could do it this way. :)
Maybe.
> What I suggest is running the validations before storing the new data in the
> session.
Well, this is what I was trying to do actually, but in the process I
lost the functionality of the validation functions. I hope what you
are suggesting really works! Have you been using this system in your
apps?
> That way you can validate that everything is OK before "committing"
> to the session scope.
Exactly! Validating before even saving to the session scope would be
even better!
> I believe that you can wrap everything in
> <cftransaction> tags in case you need to roll back during the transaction.
I need to check out what are the <cftransaction> for. Also I am not
sure if I understand the "roll back during the transaction"
expression.
> This is where Raul's example above would come in handy, but with calling
> valid() instead of save().
Which example were you referring to?
> As for displaying error messages, there are a lot of ways to skin that cat.
> I happen to like the simplicity of errorMessagesFor(),
Exactly! I would be glad if we could keep this function working in
every scenario. :)
> so I have an array
> called errorModelObjects that my layout file looks for. Whenever a model
> object fails validation, I just add it to the errorModelObejcts array from
> the controller and let the layout handle it from there.
Nice! I am going to study your code and maybe later come back with
questions. You might say: "OH NOOOO! MORE QUESTIONS?!" :)))))))
For now, lEt this be all for now. I hope I am not being too annoying
with my questions and problems, but I am really excited about the new
stuff that I am learning.
Ever since I started using ColdFusion a year ago I always said that
this community is the best. However we could freely add the Wheels
community to that statement. :) Thank you guys for helping. It is very
nice to know that there is someone to ask for help, especially after a
long night unsuccessfully to solve your problem.
P.S. I someone wants to check, I am putting some of my ideas in my
blog:
http://combofusion.posterous.com. Feel free to comment and
spread the words. Maybe one day someone would find my blog useful
too. :)