0

I am using Google app engine and I want to redirect to another page with a parameter when a form submited.

Here is the first form:

<form method="post" class="form-inline pull-left">
   <div class="input-append">
     <input type="text" required name="askquestion" class="span5"/>
     <button type="submit" name="askbutton"  class="btn-u" value="askbutton">Ask</button>
   </div>
</form>

And here the backend:

askbutton = self.request.get("askbutton")
if askbutton:
  title = self.request.get("askquestion")
  self.render("makeaquestion.html",title=title)

I have already tried another one:

self.redirect("/makeaquestion?title='%s'"%title)

The first one render the new html and pass the parameter but the url stay the same as before. The second one redirect to the new url but without passing the parameter.

2 Answers 2

2

Set the action attribute of your form:

<form action="/makequestion" method="post" class="form-inline pull-left">
   <div class="input-append">
     <input type="text" required name="askquestion" class="span5"/>
     <button type="submit" name="askbutton"  class="btn-u" value="askbutton">Ask</button>
   </div>
</form>

This will submit a post request (with the filled-in data) to /makequestion

Sign up to request clarification or add additional context in comments.

Comments

0

Your second method: self.redirect("/makeaquestion?title='%s'"%title) should be successful if you are pulling the params from the url in your Handler:

 class HandleMakeQuestion(webapp2.RequestHandler):
    def get(self, params):
        title = self.request.get('title')
        logging.info("Title: %s" %(title))

This may also require some regex in your Handler Routing:

app = webapp2.WSGIApplication([('/makeaquestion([^/]+)', HandleMakeQuestion)])

2 Comments

Second method was a redirect which included params in the url: Get.
Correct and he wanted to pass it as POST.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.