The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
First, go to the Sitefinity backend in Administration >> Settings switch to Advanced Settings and browse Toolboxes >> FormControls >> Sections >> Common >> Tools (this will register a RadCaptcha control inside Common section)
Click Create new and set Control CLR Type or Virtual Path to Telerik.Web.UI.RadCaptcha, Telerik.Web.UI put a name (without spaces) and a title for the UI.
Next step is to implement new form control to fire RadCaptcha validation.
In Visual Studio add a project library. Add all necessary .dll dependencies (Telerik.Sitefinity.dll, Telerik.Web.UI.dll) found in SitefinityWebApp\bin. Add this library as a reference in SitefinityWebApp in order to be accessible in Sitefinity.
Code:
using
System;
using
System.ComponentModel;
using
System.Linq;
using
Telerik.Sitefinity.Modules.Forms.Web.UI;
using
Telerik.Sitefinity.Services;
using
Telerik.Sitefinity.Web.UI;
using
Telerik.Web.UI;
namespace
NewFormControl
{
public
class
FormControlWithCaptcha:FormsControl
{
private
readonly
string
captchaErrorMessage =
"Invalid Code, please try again"
;
private
RadCaptcha captcha;
protected
RadCaptcha MyCaptcha
{
get
{
if
(!SystemManager.IsDesignMode)
{
//retrieve the captcha control from the list of controls in the form
foreach
(
object
control
in
base
.FormControls.Controls[1].Controls)
{
if
(control.GetType() !=
typeof
(RadCaptcha))
{
continue
;
}
this
.captcha = control
as
RadCaptcha;
break
;
}
}
return
this
.captcha;
}
}
protected
override
void
InitializeControls(GenericContainer container)
{
if
(!SystemManager.IsDesignMode)
{
base
.InitializeControls(container);
base
.BeforeFormSave +=
new
EventHandler<CancelEventArgs>(
this
.FormsControlCustom_BeforeFormSave);
}
}
protected
void
FormsControlCustom_BeforeFormSave(
object
sender, CancelEventArgs e)
{
if
(
this
.MyCaptcha !=
null
&& !
this
.MyCaptcha.IsValid)
{
e.Cancel =
true
;
this
.MyCaptcha.ErrorMessage =
this
.captchaErrorMessage;
}
}
}
}
The referenced project must be built under .NET 4.0 (if the target framework is 4.5 it will be incompatible with SitefinityWebApp)
Register this new form control as a page control.
Go to Administration >> Settings switch to Advanced Settings and browse Toolboxes >> PageControls >> Sections >> ContentToolboxSection >> Tools
Click Create new and set Control CLR Type or Virtual Path to NewFormControl.FormControlWithCaptcha put a name (without spaces) and a title for the UI.
As a result we got fully working form control with captcha:
Here you can download the complete sample.
Stanislav Velikov is a Tech Support Engineer at Telerik. He joined the Sitefinity Support team in April 2011.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.