Get data from WTForms form

user7209225 picture user7209225 · Dec 1, 2016 · Viewed 10k times · Source

How do I get the data from a WTForms form after submitting it? I want to get the email entered in the form.

class ApplicationForm(Form):
    email = StringField()

@app.route('/', methods=['GET', 'POST'])
def index():
    form = ApplicationForm()

    if form.validate_on_submit():
        return redirect('index')

    return render_template('index.html', form=form)
<form enctype="multipart/form-data" method="post">
    {{ form.csrf_token }}
    {{ form.email }}
    <input type=submit>
</form>

Answer

davidism picture davidism · Dec 1, 2016

Each field has a data attribute containing the processed data.

the_email = form.email.data

Working with form data is described in the getting started doc.