views:

1066

answers:

1

I have a form that POSTs information to one of my handlers. My handler verifies the information and then needs to POST this information to a third party AND redirect the user to that page.

Example of the

    class ExampleHandler(BaseRequestHandler):
  """DocString here...
  """
  def post(self):
    day = int(self.request.get('day'))
    checked_day = CheckDay(day)
    if checked_day:
      #Here is where I would like to redirect the user to the 3rd party -- but via a post as I will be submitting a form based on data in checked_day on their behalf.
    else:
      # Otherwise no post redirect is needed  -- just a simple self.redirect.
      self.redirect('/example')

Do you have any advice on how I can redirect the user to the page where I have submitted a form?

I would ideally like a self.redirect() that allowed POSTs to 3rd party sites but I don't believe this is an option.

My goal is to check the data provided before sending them along to the 3rd party. Are their other options I am missing?

Thank you

A: 

You can POST the form and redirect the user to a page, but they'll have to be separate operations.

The urlfetch.fetch() method lets you set the method to POST like so:

import urllib

form_fields = {
  "first_name": "Albert",
  "last_name": "Johnson",
  "email_address": "[email protected]"
}
form_data = urllib.urlencode(form_fields)
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
result = urlfetch.fetch(url=url,
                        payload=form_data,
                        method=urlfetch.POST,
                        headers=headers)

The above example is from the URL Fetch Python API Overview.

a paid nerd
Thank you. This is helpful. In my case I can't submit the form and redirect the user -- as the user needs to interact with the page that is returned from the submitted form. You do answer the root question so thank you again.
Wasauce