[development] Temporary form data storage ... and avoiding validation
Pierre Rineau
pierre.rineau at makina-corpus.com
Wed Aug 11 09:59:21 UTC 2010
Le mardi 10 août 2010 à 22:12 -0400, Jeff Greenberg a écrit :
>
> So, two questions. Is form_state going to persist the user data for me
> between form loads, or is there a better method? And I've run into an
> interesting problem in that the portion of the form with required fields
> (name, etc) doesn't need to be filled in until the user wants to submit,
> but of course, that ends up throwing an error when the form is
> 'submitted' due to one of the other buttons being clicked. Is there a
> way to have those buttons cause a submit, but bypass validation?
In order to bypass validation, may be you can remove the required
attribute of your form fields, and check for them not be empty in a
custom validation handler.
You can safely use the form_state array to store your temporary data,
but remember that the form cache has only 6 hours to live.
I'd create a custom cache table (using the system module table schema
definition, with another name), then use it to store my data using each
step form submit or validation handler without setting any lifetime.
If you create such cache table, it won't be erased by the cron unless
you implement the hook_flush_caches() in order to do it.
Cache tables are meant to store temporary data which you are be able to
rebuild, and can be safely dropped. So, if the data is temporary user
input, you can create a cache table and use it with custom queries (not
using cache_get() and cache_set()) if you really meant to store this
into database, this will allow you to bypass mecanisms such a memcache
storage and ensure your data won't be lost.
Pierre.
More information about the development
mailing list