I have written the following code where a submit action with the value {{category.name}} unexpectedly triggers the “create” button in form_category, resulting in a “Please enter a name” message.
This approach worked fine in a previous project using the same logic. I’ve confirmed that the urls.py is properly set up. What could be the issue?
<form method="POST">
{% csrf_token %}
category name: {{ form_category }}
<input type="submit" value="create" formaction="{% url 'mk_category' %}">
<span> | </span>
{% for category in categories %}
<input type="submit" value="{{category.name}}" formaction="{% url 'index_with_category' category.id %}">
{% endfor %}
</form>
Thank you very much for your help!
Wrapping each submit button in separate form tags resolves the issue. However, I plan to continue using multiple submit buttons within a single form in the future. I have checked urls.py multiple times and found no issues.
Please help me with this.
James yun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.