Two submit buttons in one form

前端 未结 19 2100
不思量自难忘°
不思量自难忘° 2020-11-21 23:23

I have two submit buttons in a form. How do I determine which one was hit serverside?

19条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 00:00

    You can present the buttons like this:

    
    
    

    And then in the code you can get the value using:

    if request.method == 'POST':
        #valUnits = request.POST.get('unitsInput','')
        #valPrice = request.POST.get('priceInput','')
        valType = request.POST.get('typeBtn','')
    

    (valUnits and valPrice are some other values I extract from the form that I left in for illustration)

提交回复
热议问题