librelist archives

« back to archive

How to add fields to a request?

How to add fields to a request?

From:
Jean Jordaan
Date:
2015-04-10 @ 11:36
Hi all

I posted the following to
http://stackoverflow.com/questions/29559860/how-to-add-fields-to-a-request as
well.

I have a login page. Upon submission if 'webmail' is selected, the request
should be redirected to the webmail server, with the credentials submitted but
under different keys. Here's what I'm trying now:

    if form.validate_on_submit():
        if form.destination.data == 'webmail':
            form.rc_user.data = form.email.data
            form.rc_password.data = form.password.data
            return redirect('https://example.com/webmail/', code=307)

This almost works: the POST is redirected to webmail. However the values
submitted are the default values, not the assigned values.

I have some more issues though:

- the keys should be _user and _pass, but Flask seems to blow up with
  leading-underscore field names.

- I do not want to add these fields to the original class. I want to subclass
  upon submission, somewhat as follows:

    if form.validate_on_submit():
        if form.destination.data == 'webmail':
            class WebmailLoginForm(LoginForm):
                rc_user = EmailField('user', default=form.email.data)
            form = WebmailLoginForm(request.form)
            return redirect('https://example.com/webmail/', code=307)

When I do this, the added fields are not submitted.

I also tried messing with `request.form` (e.g. replacing the ImmutableDict with
my dict), but so far that hasn't worked either.

-- 
jean                                              . .. .... //\\\oo///\\