[Catalyst] Formhandler and Auth

Eric Berg eberg at bergbrains.com
Mon Mar 7 00:03:37 GMT 2011


On 3/4/11 11:03 AM, Gerda Shank wrote:
> On 3/4/11 8:23 AM, Eric Berg wrote:
>> I'm trying to do some progressive engagement by allowing one of my 
>> forms to be filled out before a user is required to log in, but once 
>> the form is filled, I need them to log in so that I can get the user 
>> ID, which is part of the record for that form's row in my db.
> So after the form is submitted, you want to save the form contents 
> somehow, then present a login form, then after the user logs in, save 
> it to the database?
Yes.  What I did previously was just to save a hash of the values, but 
I'm not sure how to pass that to formhandler given that my db 
constraints currently require the values for this form to have a 
creator_id, which is just what I need from the login.  So, I'm thinking 
at this point that I need to find a way to pass a hash of form values 
back to formhandler..that's got to be possible, and must be done after I 
get the form submission or I'll have to loosen up the constraints on my 
db to allow me to insert rows without a creator ID.  I'm looking into 
that now.
>
> Is the part you're not sure of how/where to save the form contents? 
> There are the usual options for preserving data across several 
> requests, i.e. stash, database, etc.
I've been stashing a hash of form params.  I have to test this out, but 
I have to figure out if I can validate the form without the creator_id's 
being present.  I added it to the form, because formhandler was barfing 
when I used the simple form of stashing the new_result({}), then 
returning $self->form($c) in my add().   I have to figure out how to 
validate the form wtihout having it submitted to teh db, because that 
causes an error when the creator_id is missing, or add the creator_id 
(hidden and empty) to the form and only validate after login.  I guess I 
just have to try a few things.  If any of you good folks have banged 
your head against this and have ideas, they'd certainly be welcome.
>
> Then you'd have to decide how you want to save the data. You *could* 
> use FormHandler to do that, but if you have an already validated set 
> of data, it might be simpler to just save it to the database yourself.
May be.  Probably, since I'm trying to wrest control from formhandler so 
I can validate a form without the creator_id, then redirect to login, 
then take the values of the form and the logged-in user's id and commit 
that to the db.  One change that is causing me problems is that I moved 
from the approach of having the form be a simple attribute (has 'form') 
where I was doing all the processing in the show and add methods to the 
approach where I implemented $self->form() per the sample referenced in 
HTML::FormHandler::Manual::Catalyst.

Thinking through this in writing this, I believe that what I have to do 
is reimplement the form as a simple attribute and then handle the 
process() as needed in the add() method.  I think that's where I shot 
myself in the foot.

Thank you muchly.  I'll post my successful results for the benefit of 
those who follow.

Eric
>
> I'm not quite sure if I addressed the particular issues you were 
> having; if not, please clarify :)
>
> Gerda
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: 
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/




More information about the Catalyst mailing list