N
N
nurzhannogerbek2018-03-15 07:50:09
Django
nurzhannogerbek, 2018-03-15 07:50:09

Form with two submit | Django?

Hello! Please help me figure it out.
There is a form in which it is necessary to fasten two submit buttons. By pressing each of them, it is necessary to process the data of certain fields. An Internet search says that you need to specify an attribute with different names on these submits and namecheck in the view whether this name is in request.POST. I am using the following code and it does not work correctly. Request.POST does not have these names that I specified for the submit buttons. What am I doing wrong to solve this problem?
item_edit_form.html:

<form method="post" action="{% url 'адрес' %}" class='edit-form' enctype="multipart/form-data">
  {% csrf_token %}
  <!-- Здесь поля формы -->
  <input type="submit" class="btn btn-success" value="Удалить" name='delete_submit'/>
  <input type="submit" class="btn btn-success" value="Обновить данные" name='update_submit'/>
</form>

views.py: (Class Based View)
class ItemEditView(UpdateView):
    def form_valid(self, form):
        if 'update_submit' in self.request.POST:
            # Использовать все поля формы
        elif 'delete_submit' in self.request.POST:
            # Использовать лишь одно поле формы

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Prog, 2018-03-15
@damprog

why if 'update_submit' in self.request.POST and not if 'update_submit' in self.data ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question