[Flask] Access form data in view function

Alex Hall ahall at autodist.com
Thu Apr 21 16:02:16 EDT 2016


One more update: my form seems to only pass one field, no matter what. I
made a little loop in the function that processes the form:

 for i, j in request.form.iteritems():
  print "form[{i}]={j}".format(i=i, j=j)

This only ever prints my "orderNumber" text field, whether that field has a
value or not. It never prints the other text field in the form, the
checkbox, or either of the multiple select fields. I've been over the form
template, html, and class again and again, trying to spot what I did
differently for the orderNumber field that makes it stick when nothing else
does. I've even reversed the order of fields in the form, to see if it's
just the first field in the form that gets saved, but that didn't change
anything. I'm really at a loss, and I've spent hours googling this to no
avail. It makes no sense that the form would grab one field, but no others.
I can't figure out what I could possibly be doing, and no one I could find
has this problem. What code would it help to send to the list for you all
to look at? Thanks.

On Thu, Apr 21, 2016 at 8:13 AM, Alex Hall <ahall at autodist.com> wrote:

> Hello all,
> Further to my question about multiple select fields yesterday, how does a
> view function access form data in general? I know I use the global(?)
> request object's "form" property, but beyond that I'm not sure. I can
> access StringField values (I'm using WTF) by using request.form.fieldID.
> But single select fields, multiple select fields, the status of checkboxes
> or radio buttons, and so on I can't work out or find online. One resource
> said, for checkboxes, to use request.form.getlist("checkboxID"), but that
> gave me an empty list despite that checkbox being checked. What am I
> missing? I know people usually use validators, but I need the values and
> statuses of elements in my form-processing view function because I'm
> dynamically constructing an SQL query based on the form's information.
>
> --
> Alex Hall
> Automatic Distributors, IT department
> ahall at autodist.com
>



-- 
Alex Hall
Automatic Distributors, IT department
ahall at autodist.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20160421/36df664e/attachment.html>


More information about the Flask mailing list