To use a Captcha with Ametys 3.1

In your XSL

    <xsl:import href="plugin:cms://stylesheets/helper/common.xsl"/>
    <xsl:call-template name="captcha">
		<xsl:with-param name="key-name">captcha-key</xsl:with-param>
		<xsl:with-param name="key-id">captcha-id</xsl:with-param>

		<xsl:with-param name="value-name">captcha-value</xsl:with-param>
		<xsl:with-param name="value-id">captcha-value-id</xsl:with-param>
		<xsl:with-param name="value-style"/>
		<xsl:with-param name="value-class"/>

		<xsl:with-param name="image-alt">PLUGINS_CMS_CONTENT_COMMENTS_POST_AUTHOR_CAPTCHA</xsl:with-param>
		<xsl:with-param name="image-alt-i18n" select="true()"/>
		<xsl:with-param name="image-style">margin: 3px 0px 3px 10px;</xsl:with-param>
		<xsl:with-param name="image-class"/>

		<xsl:with-param name="js-funcname-torefresh">refresh_comment_<xsl:value-of select="$number"/></xsl:with-param>
	</xsl:call-template>

This will generate a code like

	<input type="hidden" name="captcha-key" id="captcha-id" value="STATIC-132123132"/>
	<input type="text" name="captcha-value" id="captcha-value-id" style="" class=""/>
	<img style="margin: 3px 0px 3px 10px;" class="" src="/cms/plugins/cms/captcha/STATIC-132123132/image.png" alt="ALTERNATIVE" id="id123132132132"/>

But this will above all generate a javascript version with a function (with the name you gave as "js-funcname-torefresh") to reload the captcha.

In your JAVA

Get your parameters and test this:

if (CaptchaHelper.checkAndInvalidate(captchaKey, captchaValue))
{
    // good
}
else
{
    // bad
}
Back to top