Skip to content

Instantly share code, notes, and snippets.

@uestla
Created May 6, 2012 14:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uestla/2622447 to your computer and use it in GitHub Desktop.
Save uestla/2622447 to your computer and use it in GitHub Desktop.
AntispamControl (inspired by https://gist.github.com/2388131)
<?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