fulaphex
fulaphex

Reputation: 3219

Django: getting form's name

Is it possible to get the name of the form from the request? Possibly I might want to have multiple forms on one page and each of process them differently.

<form action="." method="post" name="station_select">
<form action="." method="post" name="bike_select">

I'd want to execute some function for the case, when user selects a bike and another when he selects a station.

Upvotes: 0

Views: 84

Answers (1)

augustomen
augustomen

Reputation: 9739

No. The form name is not part of the POST request, and that is a HTTP characteristic, not Django's.

You can include a hidden element in each form though:

<form action="." method="post">
<input type="hidden" name="station_select" value="">

<form action="." method="post">
<input type="hidden" name="bike_select" value="">

And then, in the view:

if 'station_select' in request.POST:
    ...
elif 'bike_select' in request.POST:
    ...

Or, if you have a different submit button for each, they may also have names (and they could even be in the same form).

<input type="submit" name="station_select" value="Go">
<input type="submit" name="bike_select" value="Go">

Upvotes: 2

Related Questions