mardi 3 février 2015

HTML submit button submits all forms on page, not just parent, in Django webapp

I am using Django to display two forms on a single page. I am using the bootstrap filestyle for styling and django modelforms for rendering.


This is the basic layout of my two forms in my webapp


These forms are in their form tags in the html.


the top form:



<form action= "{% url 'new_page' %}" method="post" enctype="multipart/form-data">
<div class="col-md-2 col-md-offset-2" id="step-one">
{{docform.docfile}}
{% csrf_token %}
<p>{{ docform.non_field_errors }}</p>
<p>
{{ docform.docfile.errors }}
</p>
</div>
<div class="col-md-2">
<p><input class="btn btn-primary" type="submit" value="Process"/></p>
</div>
{% block down %}
{% endblock %}
</form>


and the bottom form:



<form action= "{%url 'new_enrich'%}" method="post" enctype="multipart/form-data">

...

<div class="col-md-2 col-md-offset-2 separate" id="step-one">
{{goform.docfile}}
{% csrf_token %}
<p>{{ goform.non_field_errors }}</p>
<p>
{{ goform.docfile.errors }}
</p>
</div>
<div class="col-md-1 separate">
<p><input class="btn btn-primary" type="submit" value="Enrich"/></p>
</div>
</form>


when I choose a file using the bottom upload button, the top upload button then becomes active.


enter image description here


And then when I click submit on the bottom form. The top forms error text shows up.


enter image description here


I am completely clueless as to how this is happening.


My modelForms are in two different django apps. They do not share view or form files. The correct url shows up with the warning.


Thank you for your help.





Aucun commentaire:

Enregistrer un commentaire