myMVC_module_Captcha
1.0.0
this myMVC module provides a captcha image you could use in your own html forms.
anadalemo.ttf)
into the root folder of this modulefont.ttfcd into the modules folder of your myMVC3.2.x copy; e.g.:
cd /var/www/myMVC/modules/;clone myMVC_module_Captcha as Captcha
git clone --branch 1.0.x https://github.com/gueff/myMVC_module_Captcha.git Captcha;1. add the following route to your primary working Module
// captcha route
MVCRoute::GET(
CaptchaModelIndex::$sRoute,
'CaptchaControllerIndex::index'
);2. add captcha check and creation in your primary working Module's Controller
// check if captcha is valid
if (true === CaptchaModelIndex::captchaIsValid())
{
// captcha is OK!
}
// create captcha for new
$sCaptchaText = CaptchaModelIndex::createCaptcha();3. add this captcha Formular to your Frontend template
<form action="" method="post">
<!-- captcha -->
<label for="captcha">Captcha</label>
<img src="{CaptchaModelIndex::$sRoute}">
<input type="text"
name="{CaptchaModelIndex::$sPostFieldName}"
maxlength="{CaptchaModelIndex::$iCaptchaTextLength}"
value=""
placeholder="captcha code"
autofocus
>
<!-- /captcha -->
<button type="submit">submit</button>
</form>? Note: make sure your Route allows POST method
allow POST method in Routes you want to make use of Captcha.
MVCRoute::MIX(
['GET', 'POST'],
'/',
'FooControllerIndex::index',
$oDTRoutingAdditional->getPropertyJson()
);
In your primary Module's environment config file simply change the properties of the Captcha Model Class.
Here is an Example
//-------------------------------------------------------------------------------------
// Module Captcha
// load Class
require_once $aConfig['MVC_MODULES_DIR'] . '/Captcha/Model/Index.php';
// declare a custom route
CaptchaModelIndex::$sRoute = '/captcha/MyFormularXY/';
// add some extra chars to choose from...
CaptchaModelIndex::$sChar.= '_!=)(/&%$[].:,;+*~#';
// ...if you changed the $sChar, do not forget to adjust sanitizing rule
CaptchaModelIndex::$sCharSanitizePattern = "/[^\p{L}}\p{M}\p{S}\p{N}\p{P}']+/u";
// auto-name template input var (name="") like Route
CaptchaModelIndex::$sPostFieldName = str_replace('/', '', CaptchaModelIndex::$sRoute);
// set SessionName like $sPostFieldName
CaptchaModelIndex::$sSessionName = CaptchaModelIndex::$sPostFieldName;