Differentiating POST requests for two forms on one page

68 views
Skip to first unread message

Jonathan Saewitz

unread,
Oct 30, 2015, 7:51:17 AM10/30/15
to web.py
I give users the option to register and log in on the same page — these require two forms. I'm having trouble differentiating between which form the user submitted. I considered checking if the 'username' portion of either form was blank, and if it was blank, I would know the other form was the one submitted. However, if a user started filling out the registration form and then used the log in form, this wouldn't work because neither username textbox would be blank in either form. What's the best way to go about telling which form a user submitted when there are two forms on one page?

By the way, someone had the same issue as me over four years ago, but I couldn't figure out how to do the suggestions.

Thanks.

Marios Zindilis

unread,
Oct 30, 2015, 8:05:30 AM10/30/15
to we...@googlegroups.com
If you have two forms, use two classes to process them. 

Your source code for user registration and authentication should be as simple and straight forward as possible, to reduce the probability of something going very wrong. If you try to handle two forms in one class, you will have to check a lot of conditions, as you already tried, and it will be ugly. 

If you insist on using one class, use different field IDs for each one, such as username_register Vs username_login. But again, bad idea.

--
Marios Zindilis

--
You received this message because you are subscribed to the Google Groups "web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webpy+un...@googlegroups.com.
To post to this group, send email to we...@googlegroups.com.
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/d/optout.



--
Marios Zindilis
Reply all
Reply to author
Forward
0 new messages