Reputation: 4635
Say if I have multiple forms with multiple submit button in a single page, can I somehow make all of these buttons work using webapp as backend handler? If not, what are the alternatives?
Upvotes: 2
Views: 1384
Reputation: 1705
One way to do this—that is specific to Google App Engine—is the following:
HTML forms:
<input type="submit" name="number1">
<input type="submit" name="number2">
Then add the following to your python handler:
number1_button = self.request.get('number1')
number2_button = self.request.get('number2')
if number1_button:
#number 1 was pressed
elif number2_button:
#number 2 was pressed
Upvotes: 4
Reputation: 101139
The framework you use is irrelevant to how you handle forms. You have a couple of options: you can distinguish the forms by changing the URL they submit to - in which case, you can use the same handler or a different handler for each form - or you can distinguish them based on the contents of the form. The easiest way to do the latter is to give your submit buttons distinct names or values, and check for them in the POST data.
Upvotes: 7