python - Nested Django Forms: 'ManagementForm data is missing or has been tampered with' -


so i've looked around , seems nobody has had same problem having cause seemingly common error. rendering forms in html follows:

<form method="post" action=""> {{ tags_formset.management_form }}  <!-- code displaying formset --> ... <!-- -->      <form method="post" action="">         {{ add_all_form.management_form }}         {{ add_all_form.addtagstoall }}         <input type="submit" value="add displayed applicants" />     </form>      <form method="post" action="">         {{ remove_all_form.management_form }}         {{ remove_all_form.removetagsfromall }}         <input type="submit" value="remove displayed applicants" />     </form>     <input type="submit" value="save changes" /> </form> 

when did not have 2 inner forms formset displayed correctly , submit button works submit form. when added 2nd 2 forms couple of problems occured:

-the submit button stopped working (though pressing enter while 1 of formset's fields selected still submits form

-the add_all_form's submit works , functions propperly (not problem interesting concerning next point...)

-the remove_all_form not work ad throughs 'managementform data missing or has been tampered with' validation error.

here views.py code creats forms:

    tagsformset = formset_factory(tagsform, formset=tagformset, extra=applicantquery.count())     if request.method == 'post':         tags_formset = tagsformset(request.post, request.files, prefix='tags', applicants=applicantquery)         add_all_form = tagaddallform(request.post, request.files, prefix='addform', applicants=applicantquery)         remove_all_form = tagremoveallform(request.post, request.files, prefix='removeform', applicants=applicantquery)         redirect = false         if tags_formset.is_valid():             tagform in tags_formset.forms:                 if 'tags' in tagform.cleaned_data:                     tagform.savetags()                 if 'removetags' in tagform.cleaned_data:                     tagform.deletetags()                                     redirect = true         if add_all_form.is_valid():             if 'addtagstoall' in add_all_form.cleaned_data:                 add_all_form.savetagstoall()             redirect = true         if remove_all_form.is_valid():             if 'removetagsfromall' in remove_all_form.cleaned_data:                 remove_all_form.deletetagsfromall()             redirect = true         if redirect:             return http.httpresponseredirect('')     else:         initforms = []         tags_formset = tagsformset(prefix='tags', applicants=applicantquery)         add_all_form = tagaddallform(prefix='addform', applicants=applicantquery)         remove_all_form = tagremoveallform(prefix='removeform', applicants=applicantquery) 

i literally can not figure out going wrong. don't know why add_all_form works when remove_all_form not, copy , pasted involved (if need can post code forms.py file don't think problem there...)

please help!

you should use 1 <form> tag. can have many submit button want here , can display many forms want, should inside single <form> tag.

then management data sent in form submit , issue should fixed.

<form method="post" action=""> {{ tags_formset.management_form }}  <!-- code displaying formset --> ... <!-- -->       {{ add_all_form.management_form }}     {{ add_all_form.addtagstoall }}     <input type="submit" value="add displayed applicants" />   >     {{ remove_all_form.management_form }}     {{ remove_all_form.removetagsfromall }}     <input type="submit" value="remove displayed applicants" /> <input type="submit" value="save changes" /> 

your view can remain is.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -