Move the recaptchacontrol to where you want it in your form.
If you want to use the settings you entered in the Developer section, you have to do the following in codebehind: (You alse need to add the datatype to the document type for the page which the form is rendered on)
var src = Node.GetCurrent();
var propertyAlias = "The name of the document type property"; var recaptcha = new RecaptchaControl();if (umbracoNode != null && umbracoNode.Id != 0) { // Set Values var d = new Document(umbracoNode.Id); if (d.getProperty(propertyAlias) != null) { var pt = d.getProperty(propertyAlias).PropertyType; var prevalues = PreValues.GetPreValues(pt.DataTypeDefinition.Id); // Configure control recaptcha.ID = "recaptcha_" + pt.DataTypeDefinition.Id; recaptcha.Theme = string.IsNullOrEmpty(((PreValue)prevalues[0]).Value) ? "red" : ((PreValue)prevalues[0]).Value; recaptcha.PrivateKey = string.IsNullOrEmpty(((PreValue)prevalues[1]).Value) ? string.Empty : ((PreValue)prevalues[1]).Value; recaptcha.PublicKey = string.IsNullOrEmpty(((PreValue)prevalues[2]).Value) ? string.Empty : ((PreValue)prevalues[2]).Value; recaptcha.CustomThemeWidget = string.IsNullOrEmpty(((PreValue)prevalues[3]).Value) ? string.Empty : ((PreValue)prevalues[3]).Value; recaptcha.CustomTranslations = string.IsNullOrEmpty(((PreValue)prevalues[4]).Value) ? string.Empty : ((PreValue)prevalues[4]).Value; } }
// You should change "this" below to a div inside your form
this.Controls.Add(recaptcha);
I am trying to do a similar thing but can't get it to work yet.
I installed the package, then I added the @Register and recaptcha:RecaptchaControl lines from above to my ascx and filled in the public and private keys ... that didn't work.
Do I have to use the code-behind code as well? Do I have to add a datatype to a document?
OK, I have sorted that problem (helps to check page is valid!!) but now it appears to have an image missing, underneath the help (?) icon. There is the following img tag
Unable to load one or more of the types in assembly 'Recaptcha, Version=1.0.5.0, Culture=neutral, PublicKeyToken=9afc4d65b28c38c2'. Exceptions were thrown: System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. at umbraco.BusinessLogic.Utils.TypeFinder.FindClassesMarkedWithAttribute(Assembly assembly, Type attribute) at umbraco.BusinessLogic.Utils.TypeFinder.FindClassesMarkedWithAttribute(Type attribute) at umbraco.macro.GetXsltExtensionsImpl() at umbraco.macro.<GetXsltExtensions>b__4() at umbraco.cms.businesslogic.cache.Cache.GetCacheItem[TT](String cacheKey, Object syncLock, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem) at umbraco.macro.GetXsltExtensions() at umbraco.macro.AddMacroXsltExtensions() at umbraco.macro.GetXsltTransformResult(XmlDocument macroXML, XslCompiledTransform xslt, Dictionary`2 parameters) at umbraco.macro.loadMacroXSLT(macro macro, MacroModel model, Hashtable pageElements)
how can i use it?
can you explain how to use it ?
i want to add it to a form.
Just add the included usercontrol in your form.
The form will then only validate if you enter the correct text.
Ove,
I have a form in an ascx already and want to add the recaptcha to it, how would be the best way of doing that?
Thanks
Chris
Inside your asx, add the following:
Move the recaptchacontrol to where you want it in your form.
If you want to use the settings you entered in the Developer section, you have to do the following in codebehind:
(You alse need to add the datatype to the document type for the page which the form is rendered on)
I am trying to do a similar thing but can't get it to work yet.
I installed the package, then I added the @Register and recaptcha:RecaptchaControl lines from above to my ascx and filled in the public and private keys ... that didn't work.
Do I have to use the code-behind code as well? Do I have to add a datatype to a document?
Try adding Assembly="Recaptcha" to the @Register tag and see if it works then.
OK, I now have the Captcha showing, in my form, but it doesn't stop the form from being submitted ... what else am I missing?
Do I NEED to do any of the above "code behind" stuff?
It depends. Can you post the template code? It will be easier to give a good answer. (Be sure to not post you private key)
OK, I have sorted that problem (helps to check page is valid!!) but now it appears to have an image missing, underneath the help (?) icon. There is the following img tag
<img class="externalLink" alt="external link" src="/static/img/external.gif">
If I remove it with Firebug the layout of the Captcha tool looks fine.
Any ideas on that one?!
Try replacing the recaptcha.dll in your bin folder with this one: http://recaptcha.googlecode.com/files/recaptcha-dotnet-1.0.5.0-binary.zip
Err, I now get an error (it mentions Mvc?) -
Unable to load one or more of the types in assembly 'Recaptcha, Version=1.0.5.0, Culture=neutral, PublicKeyToken=9afc4d65b28c38c2'. Exceptions were thrown:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
at umbraco.BusinessLogic.Utils.TypeFinder.FindClassesMarkedWithAttribute(Assembly assembly, Type attribute)
at umbraco.BusinessLogic.Utils.TypeFinder.FindClassesMarkedWithAttribute(Type attribute)
at umbraco.macro.GetXsltExtensionsImpl()
at umbraco.macro.<GetXsltExtensions>b__4()
at umbraco.cms.businesslogic.cache.Cache.GetCacheItem[TT](String cacheKey, Object syncLock, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem)
at umbraco.macro.GetXsltExtensions()
at umbraco.macro.AddMacroXsltExtensions()
at umbraco.macro.GetXsltTransformResult(XmlDocument macroXML, XslCompiledTransform xslt, Dictionary`2 parameters)
at umbraco.macro.loadMacroXSLT(macro macro, MacroModel model, Hashtable pageElements)
OK, panic over ... I've found the culprit ... our CSS guy! (was adding an image to all "external" links).
is working on a reply...