I have a middleware like this:
class PostModelFormMiddleware(object):
def process_request(self, request):
form = PostModelForm()
request.post_form = form
This form has a captcha field. What I want to happen in my template is everytime a person hits Submit the captch question refreshes by Javascript to a new one. How do I grab that request.post_form and its data in jQuery?
Thank you!
EDIT: More code.
The HTML:
<form id="add_post">
...
<input type="hidden" name="math_captcha_question" value="fbc9fcdffbf2b2723ab36e9f341372214daf1be936202d2035">
6 - 5 =
...
</form>
I would like to change the value of "math_captch_question" as well as the displayed text. Both of these are initially displayed using the template tag {{request.post_form.math_captcha_question}}
The jQuery:
$("form#add_post").submit(function() {
//Validations and stuff
var data = {category:category, body:body, nickname:nickname, math_captcha_question:math_captcha_question, math_captcha_field:math_captcha_field};
var args = {type:"POST", url:"add_post/", data:data, complete:function(res, status) {
//Process response
//This is where I would like to set new values for math_captcha_question
} };
$.ajax(args);
}
return false;
})
/add_post/ view:
def add_post(request):
if request.method == 'POST':
if form.is_valid():
#do stuff
return HttpResponse("success")
else:
return HttpResponseServerError("fail")