Multiple Submits in HTML Forms - Cherrypy

M

Maurice LING

Hi,

Assuming that I have this code for Cherrypy 3

class Welcome:
def index(self):
return """
<form action="btn_handler" method="POST">
<input value="Add" name="AddBtn" type="submit">
<input value="Edit" name="EditBtn" type="submit">
</form>"""
index.exposed = True

How should I write "btn_handler" so that it will perform different
actions when different button is pressed?

Thanks in advance

Cheers
maurice
 
C

Carsten Haese

Hi,

Assuming that I have this code for Cherrypy 3

class Welcome:
def index(self):
return """
<form action="btn_handler" method="POST">
<input value="Add" name="AddBtn" type="submit">
<input value="Edit" name="EditBtn" type="submit">
</form>"""
index.exposed = True

How should I write "btn_handler" so that it will perform different
actions when different button is pressed?

Something like this would do it:

def btn_handler(self, AddBtn=None, EditBtn=None):
if AddBtn:
return "You pressed Add!"
if EditBtn:
return "You pressed Edit!"

Alternatively you could use a kwargs dictionary and test it for the
presence of the "AddBtn" or "EditBtn" keys.

HTH,
 
M

Maurice LING

Carsten said:
Something like this would do it:

def btn_handler(self, AddBtn=None, EditBtn=None):
if AddBtn:
return "You pressed Add!"
if EditBtn:
return "You pressed Edit!"

Alternatively you could use a kwargs dictionary and test it for the
presence of the "AddBtn" or "EditBtn" keys.

Thank you Carsten
maurice
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top