Reputation: 721
I m using google reCaptch for captca validation and so i want to customize according to my application design. I had user html helper for google reCaptch. So how can i customize its height,width and other appearance in view using razor html helper ? Really stuck in this customization issue.
Upvotes: 0
Views: 117
Reputation: 466
I realise this post is a little old, but I've recently done something similar - so thought I could help (if you still need it)
I know you want to use the Html helpers, but having looked into this extensively - none really offer this. The reCaptcha Developers Guide has a guide as to how you can implement your own style, and validation - a good idea would be to abstract the validation to behind an interface to allow proper testing.
You can more or less copy the HTML example from the reCaptcha documentation, but the validation code would look (in a very basic form) something like this:
bool success;
const string url = "http://www.google.com/recaptcha/api/verify";
var ip = Request.UserHostAddress;
var d = new NameValueCollection
{
{ "privatekey", "6Ld-lN0SAAAAAB1c2Mzgu2pNjkLxn9W07FsAMLgc" },
{ "remoteip", ip },
{ "challenge", Request.Form["recaptcha_challenge_field"] },
{ "response", Request.Form["recaptcha_response_field"] }
};
using (var client = new System.Net.WebClient())
{
var response = client.UploadValues(url, d);
var result = Encoding.ASCII.GetString(response);
success = result.StartsWith("true");
}
if (!success)
ModelState.AddModelError("recaptcha_response_field", "Please enter the correct words");
else
Response.Write("CAPTCHA check is valid - we think you are a human");
Upvotes: 0