Michael Graham wrote:
Does anyone have used CGI::Application::Plugin::FormState together with
CGI::Application::Dispatch?

I do.  At the moment, I'm using a custom subclass of
CGI::Application::Dispatch v1, but I hope to upgrade to version 2 soon.

Here's how I handle redirects:

$self->redirect("/step2/?cap_form_state=".$self->form_state->id );

So I'm just passing cap_form_state as a regular URL query parameter. This works for me.

After successful validation of each form I use a call like:
return $self->redirect('/step2/' . $self->form_state->id);
to go to the next one, because CGI::Application::Dispatch is in use.

By C::A::Dispatch module, the 'cap_form_state' param is not set to the
$self->query object , but to $self->param
and after the redirection the new form's $self->query has a new random
string value for 'cap_form_state' param.
A call like:
$self->query->param('cap_form_state', $self->param('cap_form_state');
doesn't seem to work in the runmode (to late?)

I think this should work fine, as long as you take care to put this
value in the query object before your first call to $self->form_state.

The first time you call $self->form_state the plugin will try to fetch
the id from the query object using code like this:

   my $storage_hash  = $webapp->query->param('cap_form_state')
                     || $webapp->query->url_param('cap_form_state');


Are you calling $self->form_state->config somewhere earlier in your
app (e.g. cgiapp_init or cgiapp_prerun)?  If you are, then you need
to stuff the form state id in the query object before you do this.

And BTW, is it possible to pass hashrefs between forms, like:
$self->form_state->param('step1' => $valid_results_ref);
and retrieve in on the 'next' form? Or do I have to use something like
Storable.pm first on the hashref?

Anything you can store in the user's session should be safe to store in
a formstate param.  So the only things you should avoid are objects,
which require special care when re-vivifying.


Michael


---
Michael Graham <[EMAIL PROTECTED]>


Michael thank you for your reply.
I did find out what was happening yesterday, after looking at CAP::FormState source. The problem (as you write) was that I was calling form_state->config in the runmode prerun method, before setting the form state id to the query object. Now fixed that and everything is working nice.


But now you made me really wonder what special care do objects need...
I was about to do that, it would be convenient for me to store instances of Class::DBI into my session and re-vivifying them later on to write them to the db. Is there any suggested way to go for storing objects in session and have them back solid as they were before serialization in our session?



Regards,
Giannis


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[email protected]/
             http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to