I am trying to do a comment system with jquery and ajax, sometimes I require a user to enter a captcha image when they are posting too often.
I am using the facebox plugin for jquery with is a popup type dialog box,
I am triggering this box to open, when the backend script tells it that the user needs to enter a captcha, it then pops up the box and loads the php captcha file on screen.
This is where I am having trouble, I need the box to not only open the captcha, but to also populate the comment into this box into like a hidden form field, so that if a user enters the correct captcha code, it will then post there comment, otherwise, they are approving the captcha and then nothing will happen, so I need to then post the comment. Also if they get the captcha wrong, then I need to reload the captcha again with there comments still there, that should be easy if I can get the first part working.
Here is my code so far for this part, can anyone help?
$.ajax({
type: "POST",
url: "process.php",
data: args,
cache: false,
success: function (data) {
// there was an error so we will show an error message
if (data == 'error') {
alert(data);
//we need the user to submit a captcha to post there data
} else if (data == 'captcha') {
jQuery.facebox(function () {
jQuery.facebox({
ajax: 'captchabox.php'
})
})
//everything is all good, let post there comment
} else {
$('#comments').prepend(data);
$(this).remove();
})
};
// remove loading image
$('#load').fadeOut();
}
});