views:

43

answers:

2

Hi, I have 2 forms in my Django view. How can I do a check to see which one has been submitted?

Thanks

+1  A: 

Here are some ideas:

  • Use different action URLs for the forms, associated with different views.
  • Use different action URLs for the forms, associated with the same view but with using different parameters to the view (using the URLconf)
  • Use an <input type="hidden" /> to differentiate between the forms.

Philip

mojbro
+3  A: 

Put a different name attribute on the submit buttons for each form, then check for that key in request.POST in your view.

Also don't forget to give each form a separate prefix attribute when you instantiate them, to avoid any possible field name collisions.

Daniel Roseman
+1 for the foresight about namespace collision and prefix attribute.
Lakshman Prasad