Form sending POST request with different target URL
P粉465675962
P粉465675962 2024-03-29 17:16:07
0
1
468

I have a view that displays a form. Now, depending on which button the user selects, I want the data to be processed differently. These "different ways" correspond to the different views I want the POST request to go to.

Please help me build a form with multiple buttons that lead to different urls/views.

<form action="/your-name/" method="post">
    {% csrf_token %}
    {{ form }}
    <input type="submit" value="Process form with view ONE">
    <input type="submit" value="Process form with view TWO">
    <input type="submit" value="Process form with view THREE">
</form>

My problem is that the action attribute of the form tag defines where this POST request goes. How to change destination url with multiple buttons?

I know I can handle this logic on the server side as well. But the question is: Do Imust? If not, please show me the way

P粉465675962
P粉465675962

reply all(1)
P粉458913655

You can use ajax via the onclick attribute. post_url As such a parameter


{% csrf_token %} {{ form }}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template