How to handle multiple submits using mod_python ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poppor
    New Member
    • Dec 2006
    • 6

    How to handle multiple submits using mod_python ?

    Hi,

    if I have two submit buttons on my html page, how do I know which one is pressed when using python ?

    Example:
    <form action="test.py ">
    <input type=submit name=add value=Add>
    <input type=submit name=del value=Del>
    </form>
    ----
    def myfunction(req, var1, var2):
    ???

    I can't find anything about this in mod_python documentation, does anyone know ?

    Thanks!
    /P
  • sashi
    Recognized Expert Top Contributor
    • Jun 2006
    • 1749

    #2
    Originally posted by poppor
    Hi,

    if I have two submit buttons on my html page, how do I know which one is pressed when using python ?

    Example:
    <form action="test.py ">
    <input type=submit name=add value=Add>
    <input type=submit name=del value=Del>
    </form>
    ----
    def myfunction(req, var1, var2):
    ???

    I can't find anything about this in mod_python documentation, does anyone know ?

    Thanks!
    /P
    Hi there,

    Am not sure about this too, i suggest to use javascript to handle this issue. Good luck & Take care.

    Comment

    • poppor
      New Member
      • Dec 2006
      • 6

      #3
      Originally posted by sashi
      Hi there,

      Am not sure about this too, i suggest to use javascript to handle this issue. Good luck & Take care.
      But there must be a way to do this in Python. Maybe a separate form for each button ? I'm going to google some more :)

      Thanks!
      /P

      Comment

      • poppor
        New Member
        • Dec 2006
        • 6

        #4
        Oh.. it was so simple. Here's the solution.
        If you have several submit buttons, all you have to do is go by there value.
        Example:

        mysite.html
        -------------------
        <form action=myscript .py method="POST">
        Button1:<input type=submit name=submitter value=1>
        Button2:<input type=submit name=submitter value=2>
        </form>

        myscript.py
        ------------------
        def index(req, submitter):
        if submitter = 1:
        s = "Button 1 is pressed"
        else:
        s = "Button 2 is pressed"
        return s


        Regards
        /P

        Comment

        • sashi
          Recognized Expert Top Contributor
          • Jun 2006
          • 1749

          #5
          Originally posted by sashi
          Hi there,

          Am not sure about this too, i suggest to use javascript to handle this issue. Good luck & Take care.
          Hi there,

          Why not try asking in Python forum section? Good luck & Take care.

          Comment

          Working...