myMVC_module_Captcha
1.0.0
Modul MyMVC ini menyediakan gambar captcha yang dapat Anda gunakan dalam formulir HTML Anda sendiri.
anadalemo.ttf ) ke dalam folder root modul inifont.ttf CD ke folder modul dari copy myMVC3.2.x Anda; misalnya:
cd /var/www/myMVC/modules/ ; klon myMVC_module_Captcha sebagai Captcha
git clone --branch 1.0.x https://github.com/gueff/myMVC_module_Captcha.git Captcha ; 1. Tambahkan rute berikut ke modul kerja utama Anda
// captcha route
MVC Route:: GET (
Captcha Model Index:: $ sRoute ,
' CaptchaControllerIndex::index '
);2. Tambahkan cek dan pembuatan captcha di pengontrol modul kerja utama Anda
// check if captcha is valid
if ( true === Captcha Model Index:: captchaIsValid ())
{
// captcha is OK!
}
// create captcha for new
$ sCaptchaText = Captcha Model Index:: createCaptcha ();3. Tambahkan captcha ini formular ke template frontend Anda
< 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 > ? Catatan: Pastikan rute Anda memungkinkan metode POST
Izinkan metode POST di rute yang ingin Anda gunakan captcha.
MVCRoute::MIX(
['GET', 'POST'],
'/',
'FooControllerIndex::index',
$oDTRoutingAdditional->getPropertyJson()
);
Dalam file konfigurasi lingkungan modul utama Anda cukup ubah properti kelas model captcha.
Inilah contohnya
//-------------------------------------------------------------------------------------
// Module Captcha
// load Class
require_once $ aConfig [ ' MVC_MODULES_DIR ' ] . ' /Captcha/Model/Index.php ' ;
// declare a custom route
Captcha Model Index:: $ sRoute = ' /captcha/MyFormularXY/ ' ;
// add some extra chars to choose from...
Captcha Model Index:: $ sChar .= ' _!=)(/&%$[].:,;+*~# ' ;
// ...if you changed the $sChar, do not forget to adjust sanitizing rule
Captcha Model Index:: $ sCharSanitizePattern = " /[^ \ p{L}} \ p{M} \ p{S} \ p{N} \ p{P}']+/u " ;
// auto-name template input var (name="") like Route
Captcha Model Index:: $ sPostFieldName = str_replace ( ' / ' , '' , Captcha Model Index:: $ sRoute );
// set SessionName like $sPostFieldName
Captcha Model Index:: $ sSessionName = Captcha Model Index:: $ sPostFieldName ;