How to create custom validation rulles 28/10/2014
Constants (DOMAIN, USER_IN_DOMAIN) contain name of static function, that call for validation.
Example “user in domain”, show us, how work with parameters.
class DomainsRules { const DOMAIN = 'DomainsRules::validateDomain'; const USER_IN_DOMAIN = 'DomainsRules::validateUserInDomain'; public static function validateDomain(\Nette\Forms\IControl $control) { // dump($control->getValue()); // return TRUE or FALSE } public static function validateUserInDomain(\Nette\Forms\IControl $control, $domain) { // dump($control->getValue()); // return TRUE or FALSE } } $form->addText('domain', 'Domain:') ->addRule(DomainsRules::DOMAIN, 'fill domain in format domain.
Constants (DOMAIN, USER_IN_DOMAIN) contain name of static function, that call for validation.
Example “user in domain”, show us, how work with parameters.
class DomainsRules
{
const DOMAIN = 'DomainsRules::validateDomain';
const USER_IN_DOMAIN = 'DomainsRules::validateUserInDomain';
public static function validateDomain(\Nette\Forms\IControl $control)
{
// dump($control->getValue());
// return TRUE or FALSE
}
public static function validateUserInDomain(\Nette\Forms\IControl $control, $domain)
{
// dump($control->getValue());
// return TRUE or FALSE
}
}
$form->addText('domain', 'Domain:')
->addRule(DomainsRules::DOMAIN, 'fill domain in format domain.tld');
$form->addText('user', 'User:')
->addRule(DomainsRules::USER_IN_DOMAIN, 'user is not in domain nette.org', 'nette.org');