Multiple Submits in HTML Forms - Cherrypy

Carsten Haese carsten at uniqsys.com
Tue Mar 18 03:30:58 EDT 2008


On Tue, 2008-03-18 at 07:14 +0000, Maurice LING wrote:
> 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,

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list