Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling Disabled & Readonly Fields #217

Closed
pawl opened this issue Sep 4, 2015 · 3 comments
Closed

Handling Disabled & Readonly Fields #217

pawl opened this issue Sep 4, 2015 · 3 comments

Comments

@pawl
Copy link
Contributor

pawl commented Sep 4, 2015

Currently, if you create a field with {{ form.myfield(readonly=true) }} or {{ form.myfield(disabled=true) }} you still need to do this to prevent the disabled/readonly fields from getting saved:

def edit_team():
    form = TeamForm(request.POST, obj=team)
    del form.myfield
    if request.POST and form.validate():
        form.populate_obj(team)
        return redirect('/teams')
    return render('edit_team.html')

Would it cause any problems if WTForms deleted disabled/readonly fields from the form by default (to improve security)?

@crast
Copy link
Contributor

crast commented Dec 15, 2015

This is intentional

Read my post here: http://stackoverflow.com/a/16576294/244393
(also links etc)

@crast crast closed this as completed Dec 15, 2015
@cancan101
Copy link

I read the SO post and the link about read only fields but I still don't get why this can't be done using a flag on the field. I am looking at the code here:

for name, field in iteritems(self._fields):
field.populate_obj(obj, name)
and it seems like there should be some way for the field to skip over setting the value on the object (regardless of whatever is received from the browser).

@augnustin
Copy link

augnustin commented Jun 2, 2021

👍 with @cancan101 comment:

why not adding a:

email = StringField('Email', [validators.required()], protected=True)

that would make sure email can't be populated when calling populate_obj?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants