W
W
wolverine7772021-03-13 16:05:21
Flask
wolverine777, 2021-03-13 16:05:21

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

1 answer(s)
W
wolverine777, 2021-03-13
@wolverine777

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')

in app.py
dob=form.dt.data.strftime('%Y-%m-%d')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question