Server side form validation and POST data

Posted by tomcritchlow on Stack Overflow See other posts from Stack Overflow or by tomcritchlow
Published on 2010-12-28T09:48:28Z Indexed on 2010/12/28 9:53 UTC
Read the original article Hit count: 303

Hi, I have a user input form here:

http://www.7bks.com/create (Google login required)

When you first create a list you are asked to create a public username. Unfortuantely currently there is no constraint to make this unique. I'm working on the code to enforce unique usernames at the moment and would like to know the best way to do it.

Tech details: appengine, python, webapp framework

What I'm planning is something like this:

  • first the /create form posts the data to /inputlist/ (this is the same as currently happens)
  • /inputlist/ queries the datastore for the given username. If it already exists then redirect back to /create
  • display the /create page with all the info previously but with an additional error message of "this username is already taken"

My question is:

  1. Is this the best way of handling server side validation?
  2. What's the best way of storing the list details while I verify and modify the username?

As I see it I have 3 options to store the list details but I'm not sure which is "best":

  1. Store the list details in the session cookie (I am using GAEsessions for cookies)
  2. Define a separate POST class for /create and post the list data back from /inputlist/ to the /create page (currently /create only has a GET class)
  3. Store the list in the datastore, even though the username is non-unique.

Thank you very much for your help :)

I'm pretty new to python and coding in general so if I've missed something obvious my apologies.

Tom

PS - I'm sure I can eventually figure it out but I can't find any documentation on POSTing data using the webapp appengine framework which I'd need in order to do solution 2 above :s maybe you could point me in the right direction for that too? Thanks!

PPS - It's a little out of date now but you can see roughly how the /create and /inputlist/ code works at the moment here: 7bks.com Gist

© Stack Overflow or respective owner

Related posts about python

Related posts about google-app-engine