OK...
I downloaded and implemented this Recaptcha implementation for MVC, which uses ModelState to validate captcha control.
It works brilliantly ... unless I start using it in AJAX form.
In a nutshell, when a div is redrawn using AJAX, the ReCaptcha that it should contain does not appear, although the corresponding one <scripts>is in the source after partial rendering.
The code is below.
using (Ajax.BeginForm("CreateComment", "Blog",
new AjaxOptions() { HttpMethod = "POST",
UpdateTargetId = "CommentAdd", OnComplete="ReloadRecaptcha",
OnSuccess = "ShowComment", OnFailure = "ShowComment",
OnBegin = "HideComment" }))
{%>
<fieldset class="comment">
<legend>Add New Comment</legend>
<%= Html.ValidationSummary()%>
<table class="postdetails">
<tbody>
<tr>
<td rowspan="3" id="blahCaptcha">
<%= Html.CreateRecaptcha("recaptcha", "blackglass") %>
</td>
.... Remainder of Form Omitted for Brevity
I confirmed that the form is perfectly functional when Recaptcha Control is missing and Javascript calls in AjaxOptionswork fine.
, ModelState Recaptcha - , ActionResult .
[RecaptchaFilter(IgnoreOnMobile = true)]
[HttpPost]
public ActionResult CreateComment(Comment c)
{
if (ModelState.IsValid)
{
try
{
return Content("Thank You");
}
catch
{
ModelState.AddRuleViolations(c.GetRuleViolations());
}
}
else
{
ModelState.AddRuleViolations(c.GetRuleViolations());
}
return View("CreateComment", c);
}
InValid , - ReCaptcha Control . <script> <noscript> HTML, HTML Helper , ,
<%= Html.CreateRecaptcha("recaptcha", "blackglass") %>
, - , DOM AJAX, .
HTML, javascript OnComplete= Captcha , script , . OnComplete.
function ReloadRecaptcha() {
Recaptcha.create("my-pub-key", 'blahCaptcha', {
theme: 'blackglass'
});
}
- ?
,
Eoin C