Forum

Banshee Framework Captcha

René
10 January 2014, 21:04
Hi, Hugo,

My contact form is working fine and now I would like to add captcha validation to it.

In my contact model under contact_oke I have:
		if (($contact["captcha"]) == false)
{
$this->output->add_message("Hmm... Who are you, Rocky? Please, enter the correct captcha code");
$result = false;

}
// This works


In my contact view:
<form action="/{/output/page}" method="post" class="forms forms-columnar">
...
<p>
<img src="/captcha.png" alt="captcha" />
</p>
// Validation doesn't show up
<xsl:if test="valid">
<p>Code of previous captcha correct: <xsl:value-of select="valid" /></p>
</xsl:if>

<p>Enter captcha code: <input type="text" name="code" />
<input type="submit" name="submit_button" value="Verzenden" class="btn btn-round" />
</p>
</form>


Since the contact_controller doing the post request method. I left this untouched for the moment.

Looking at the demos_captcha_controller. I was expecting the same code as in the captcha_controller but the code in the captcha_controller is to show the captcha image and is not used for validation, am I right?
Hugo Leisink
10 January 2014, 21:15
How the captcha demo works: a visitor visits the page. The view contains a captcha image. This image is generated by the 'captcha' module, which consists of only a controller. This captcha controller uses the captcha library, which generates a code, stores it in $_SESSION and renders the captcha image.

Upon submit, the captcha demo controller calls the valid_code function of the captcha library to see if the captcha was entered correctly. This is done by comparing the string submited via POST and the one in $_SESSION.
René
10 January 2014, 21:29
I have the captcha image showing on my contact form and the form validation is working through my contact model. The last thing is to take the code from the demos captcha controller and put this in my contact controller?
Great explnation btw...
Hugo Leisink
10 January 2014, 21:32
You don't have to handle any code, the captcha library does that for you. All you have to do is two things:
1) Include the image /captcha.png in your form.
2) Check the submitted code via captcha::valid_code(). This function returns a boolean.
René
11 January 2014, 15:38
Ok, I have the captcha image in my form and form-validation on the captcha field works but the captcha image won't validate.
What do you mean by:

2) Check the submitted code via captcha::valid_code(). This function returns a boolean.


Where do I put this code?
Could you give me an example...

Thanks.
René
13 January 2014, 23:47
Got it working!
René
14 January 2014, 19:42
Skip the last question. That was stupid. I have posted a little howto on my website.
This topic has been closed.