- Autor: Pavel Máca, 2010 http://www.inseo.cz
- Licence: MIT License
- Github: http://github.com/PavelMaca/CaptchaControl
Captcha Control for Nette Framework
- **Nette Framework 2.0 Beta
- PHP 5.3 ( or PHP 5.2 if you remove namespace)
The best way to install is using Composer. Add the following repository to composer.json
:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/PavelMaca/CaptchaControl.git"
}
]
and run:
$ composer require pavelmaca/captcha-control:@dev
First you must register method addCapcha to Nette\Forms\FormContainer (best place is bootstrap.php)
PavelMaca\Captcha\CaptchaControl::register(Nette\Http\Session $session);
Usage:
$form = new \Nette\Application\UI\Form;
$form->addCaptcha('captcha')
->addRule(\Nette\Forms\Form::FILLED, "Rewrite text from image.")
->addRule($form["captcha"]->getValidator(), 'Try it again.')
->setFontSize(25)
->setLength(10) //word length
->setTextMargin(20) //px, set text margin on left and right side
->setTextColor(\Nette\Image::rgb(0,0,0)) //array("red" => 0-255, "green" => 0-255, "blue" => 0-255)
->setBackgroundColor(\Nette\Image::rgb(240,240,240)) //array("red" => 0-255, "green" => 0-255, "blue" => 0-255)
->setImageHeight(50) //px, if not set (0), image height will be generated by font size
->setImageWidth(0) //px, if not set (0), image width will be generated by font size
->setExpire(10) //ms, set expiration time to session
->setFilterSmooth(false) //int or false (disable)
->setFilterContrast(false) //int or false (disable)
->useNumbers(false); // bool or void
Global setting:
CaptchaControl::$defaultFontSize = 30;
CaptchaControl::$defaultFilterSmooth = 10;
etc...
Default font file is /fonts/Vera.ttf
You can change it by $form['captcha']->setFontFile($path)
(or as global CaptchaControl::$defaultFontFile = $path
)