These instructions are specific for DNN Forums, but you can use the same techniques for other DNN modules.
Prerequisites
- A DNN website with the DNN Forum module installed.
- The DNN Forum source code (I'm working with release 5.00.01).
- Basic VB.NET programming skills.
- Basic ASP.NET skills.
The first step (the easy part), is to edit the post page so that it contains the reCAPTCHA control.
- Visit the reCAPTCHA website, create an account and generate the requisite keys.
- Download recaptcha.dll and place it in your sites bin directory.
- Add the following line to the top of the Forum_PostEdit.ascx:
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>
- In Forum_PostEdit.ascx, locate the <tr id="rowModerate" ...> element, and immediately after, insert a new <tr> containing the recaptcha control:
<tr> <td align="center" width="100%"> <recaptcha:RecaptchaControl ID="recaptcha1" runat="server" Theme="red" PublicKey="[YourKey]" PrivateKey="[YourKey]" /> </td> </tr>
Now we will add logic so that the post does not get submitted if the reCAPTCHA is not complete.
- Open the DotNetNuke.Forum project in Visual Studio.
- Add a reference to recaptcha.dll.
- In Forum_PostEdit.ascx.vb, add the following line somewhere to the class body:
Protected WithEvents recaptcha1 As Recaptcha.RecaptchaControl
- Find cmdSubmit_Click(...), and add the following code to the start of the method:
If Not recaptcha1.IsValid Then Return End If
The problem is that the user only gets one try - after the first attempt, the reCAPTCHA control will disappear.
This is a side effect of the UpdatePanel used in DNN to prevent the entire page from being posted when the user clicks post.
To work around this problem, we will now add a PostUpdateTrigger to the UpdatePanel to force a full PostBack when the user clicks Submit.
- Add the following two functions to Forum_PostEdit.ascx.vb:
Private Function findUpdatePanelParent(uc As Control) As UpdatePanel If TypeOf uc Is UpdatePanel Then Return DirectCast(uc, UpdatePanel) End If Return findUpdatePanelParent(uc.Parent) End Function Private Sub registerFullPostback() Dim updatePanel As UpdatePanel = findUpdatePanelParent(Me) Dim trig As PostBackTrigger = New PostBackTrigger() trig.ControlID = "Forum_PostEdit$cmdSubmit" updatePanel.Triggers.Add(trig) End Sub
- Locate Page_Init(...), and add the following line:
registerFullPostback()
No comments:
Post a Comment