Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8910139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:36:44+00:00 2026-06-15T03:36:44+00:00

I am using WTForms, and I have a problem with hidden fields not returning

  • 0

I am using WTForms, and I have a problem with hidden fields not returning values, whereas the docs say they should. Here’s a simple example:

forms.py:

from wtforms import (Form, TextField, HiddenField)

class TestForm(Form):
    fld1 = HiddenField("Field 1")
    fld2 = TextField("Field 2")

experiment.html:

{% from "_formshelper.html" import render_field %}
<html>
    <body>
        <table>
        <form method=post action="/exp">
            {% for field in form %}
                {{ render_field(field) }}
            {% endfor %}
            <input type=submit value="Post">
        </form>
        </table>        
    </body>
</html>

(render_field just puts the label, field and errors in td tags)

experiment.py:

from flask import Flask, request, render_template

from templates.forms import *
from introspection import *

app = Flask(\__name__)                  
app.config.from_object(\__name__)
db_session = loadSession()

@app.route('/exp', methods=['POST', 'GET'])
def terms():
    mydata = db_session.query(Peter).one()
    form = TestForm(request.form, mydata)
    if request.method == 'POST' and form.validate():
        return str(form.data)
    return render_template('experiment.html', form = form)

if __name__ == '__main__':
    app.run(debug = True)  

mydata returns the only row from a table that has 2 fields, fld1 and fld2. fld1 is an integer autoincrement field. The form is populated with that data, so if I run experiment.py, when I submit the form I get:

{‘fld2′: u’blah blah blah’, ‘fld1′: u’1’}

But if I change fld1 to HiddenField, when I hit submit, I get:
{‘fld2′: u’blah blah blah’, ‘fld1’: u”}

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:36:46+00:00Added an answer on June 15, 2026 at 3:36 am

    I suspect your hidden field is either (1) not getting a value set, or (2) the render_field macro isn’t building it correctly. If I had to bet, I’d say your “mydata” object doesn’t have the values you expect.

    I stripped your code down to the bare minimum, and this works for me. Note I am explicitly giving a value to both fields:

    from flask import Flask, render_template, request
    from wtforms import Form, TextField, HiddenField
    
    app = Flask(__name__)
    
    class TestForm(Form):
      fld1 = HiddenField("Field 1")
      fld2 = TextField("Field 2")
    
    
    @app.route('/', methods=["POST", "GET"])
    def index():
      form = TestForm(request.values, fld1="foo", fld2="bar")
      if request.method == 'POST' and form.validate():
        return str(form.data)
    
      return render_template('experiment.html', form = form)
    
    if __name__ == '__main__':
      app.run()
    

    and

    <html>
    <body>
    <table>
        <form method=post action="/exp">
            {% for field in form %}
                {{field}}
            {% endfor %}
            <input type=submit value="Post">
        </form>
    </table>
    </body>
    </html>
    

    This gives me {‘fld2′: u’bar’, ‘fld1′: u’foo’} as I would expect.

    Check that mydata has an attribute “fld1” and it has a value. I might set it explicitly like form = TestForm(request.values, obj=mydata) – it doesn’t look like WTForms would care, but I’ve gotten burned by it being weirdly picky sometimes.

    If that doesn’t work for you, come back and post your HTML and what values mydata has.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using Java,I have to fetch multiple sets of values from an XML file to
I have a problem with WTForms validators.optional() because it stops the validation chain if
I am building an app in tornado using sqlalchemy and wtforms. I have two
Using wtforms I am trying to format the following form. So I have evrything
I'm having trouble rendering my form's fields with WTForms. I'm using it with the
I am using appengine webapp2 as wsgihandler, jinja2 as the template engine and wtforms
Using mercurial, I've run into an odd problem where a line from one committer
Using MVC2 I have an AJAX form which is posting to a bound model.
Using Core Data, I have a fetch request to fetch the minimum of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.