Answer the question
In order to leave comments, you need to log in
How to properly configure date and phone fields in wtforms?
Hello, I'm trying to figure out the fields for reg. forms - tell me what is "good practice" for:
1. Dates of birth (I left StringField for now)
2. Phones (same)
Maybe there are some elegant (popular) forms that are used in the adult world? :)
Thanks!
Here's what I have now:
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, DateTimeField
from wtforms.validators import DataRequired, Email, EqualTo # to validate the data (
# DataRequired --> NOT EMPTY,
# Email --> using an email @. etc,
# EqualTo-->pass confirm)
from wtforms import ValidationError # to check doubles in a DATABASE
class RegistrationForm(FlaskForm):
# Personal Information
first_name = StringField('First Name:',validators=[DataRequired()])
last_name = StringField('Last Name',validators=[DataRequired()])
dob = StringField('Date of Birth: ', validators=[DataRequired()])
# Account Information
email = StringField('Email: ',validators=[DataRequired(),Email(),EqualTo('email_confirm',message='Emails must match!')])
email_confirm = StringField('Re-type Email: ', validators=[DataRequired()]) # so it has to match to EqualTo('email_confirm')
password = PasswordField('Password: ',validators=[DataRequired()])
# Contact Information
address = StringField('Address: ',validators=[DataRequired()])
city = StringField('City: ',validators=[DataRequired()])
phone = StringField('Phone: ',validators=[DataRequired()])
submit = SubmitField('Register!')
Answer the question
In order to leave comments, you need to log in
Well, I figured out, for example, with the date:
in the forms:
from wtforms.fields.html5 import DateField
dob = DateField('DatePicker', format='%Y-%m-%d')
dob=form.dt.data.strftime('%Y-%m-%d')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question