public
anonymous / gist:6434167
Created

My forms.py file :)

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
from wtforms import Form, TextField, TextAreaField, SubmitField, validators, ValidationError, PasswordField
from models import db,User
 
class ContactForm(Form):
name = TextField("Name", [validators.Required("Please enter your name.")])
email = TextField("Email", [validators.Required("Please enter your email address."), validators.Email("Please enter your email address.")])
subject = TextField("Subject", [validators.Required("Please enter a subject.")])
message = TextAreaField("Message", [validators.Required("Please enter a message.")])
submit = SubmitField("Send")
 
 
 
# User submit form for the blog
 
class SignupForm(Form):
firstname = TextField("First name", [validators.Required("Please enter your first name.")])
lastname = TextField("Last name", [validators.Required("Please enter your last name.")])
email = TextField("Email", [validators.Required("Please enter your email address."), validators.Email("Please enter your email address.")])
username = TextField("Username",[validators.Required("Please enter your username.")])
password = PasswordField('Password', [validators.Required("Please enter a password.")])
submit = SubmitField("Create account")
def __init__(self, *args, **kwargs):
Form.__init__(self, *args, **kwargs)
def validate(self):
if not Form.validate(self):
return False
user = User.query.filter_by(email = self.email.data.lower()).first()
if user:
self.email.errors.append("That email is already taken")
return False
else:
return True

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.