Created
May 6, 2012 14:04
-
-
Save uestla/2622447 to your computer and use it in GitHub Desktop.
AntispamControl (inspired by https://gist.github.com/2388131)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Nette\Forms\Form, | |
Nette\Forms\Controls\TextInput; | |
class AntispamControl extends TextInput | |
{ | |
/** | |
* @return void | |
*/ | |
static function register() | |
{ | |
Form::extensionMethod('addAntispam', callback(__CLASS__ . '::addAntispam')); | |
} | |
/** | |
* @param Form | |
* @param string | |
* @param string | |
* @param string | |
* @return AntispamControl | |
*/ | |
static function addAntispam(Form $form, $name = 'antispam', $label = 'Vymažte obsah tohoto pole', $message = 'Byl detekován pokus o spam.') | |
{ | |
return $form[$name] = new static($label, NULL, NULL, $message); | |
} | |
/** | |
* @param string | |
* @param int | |
* @param int | |
* @param string | |
*/ | |
function __construct($label = NULL, $cols = NULL, $maxLength = NULL, $msg = NULL) | |
{ | |
parent::__construct($label, $cols, $maxLength); | |
$this->setDefaultValue('@'); | |
$this->addRule(Form::MAX_LENGTH, $msg, 0); | |
} | |
/** | |
* @param string | |
* @return string | |
*/ | |
function sanitize($value) | |
{ | |
return $value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment