CAPTCHA is basically few characters written on an image that a real user reads and writes into the designated text box to validate. It is assumed that an automated robots or script can't read the text on the image. If exact text of the image is written into designated text box then at form submission it is validated (generally at server side) against the CAPTCHA image text.
If both are same, the request is considered by a real user otherwise the data is ignored assuming some automated robots or scripts is making malicious request. Custom [email protected]: Password: @ViewBag.CaptchaError
SpikehI've added a TextBox called CaptchaText to capture the text input from the user. I've tried all manner of methods to retrieve the captcha object, including passing the model through to the view and controller, but it seems to lose context and create a new instanceof my object every time I click submit. I'm a bit lost.You will put the captcha text in something persistent: hidden, cookie ( both not recomended) or user sessionSpikehso I can write @Html.CaptchaFor(m = m.CaptchaText)extension methods. Add a static class with a static method this - look atseeing how MVC team wrote extensions like Html.TextBox.
This page shows you how to create a simple PHP contact form, which is pretty easy. If you want to gather more data with other types of fields, such as single-choice, multiple-choice, text box, a radio button, HTML tag or dropdown fields, you'll have to add validation and processing for these fields as well. Your Captcha has been created. Your public and private keys have been emailed to you. Hang on to that email and be sure to keep your private key a secret.
Thanks for the reply.I don't want to use persistance - I avoid it unless absolutely necessary. I want to store it in my model and retrieve it in the HttpPost action method in the controller, as I do with all other form properties.I already have a set of extension methods for the HtmlHelper class for HTML5 compatible controls.
I have plenty of experience with.Net / C#, I just don't have that much with MVC3. I was looking more for a way to implement it, suggestions on how to codeit or an explaination of the MVC framework model. If you don't want to use any persistence tool like cookies or sessions, as suggested by Andrei you can also store your object into an Hidden field.To this end you can serializw it in binary, encrypt it with some provider (symmetric, asymmetric.if you are fluent with C# you have no difficult to use them). Encription is necessary to avoid that the user might spy the right answer.
Then you encode itin bas64, that is, transform it into ASCII char, and put it int an hidden field. On post you will receive your hidden field intoyour ViewModel and can do the inverse operations. You can also write a custom model binder that do the inverse transformation on your object.With my Mvc Controls Toolkit it is easy to write an helper that does the needed transformation, and that instructs the model binder to perform the inverse transformation when the view is posted.