Home  >  Q&A  >  body text

Form sending POST request with different target URL

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粉465675962P粉465675962203 days ago425

reply all(1)I'll reply

  • P粉458913655

    P粉4589136552024-03-30 11:01:08

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

    {% csrf_token %} {{ form }}

    reply
    0
  • Cancelreply