本文整理汇总了PHP中Phalcon\Forms\Element\Text::getValidators方法的典型用法代码示例。如果您正苦于以下问题:PHP Text::getValidators方法的具体用法?PHP Text::getValidators怎么用?PHP Text::getValidators使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Forms\Element\Text
的用法示例。
在下文中一共展示了Text::getValidators方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFormValidator
public function testFormValidator()
{
$this->specify("Form validators don't work", function () {
//First element
$telephone = new Text("telephone");
$telephone->addValidator(new PresenceOf(array('message' => 'The telephone is required')));
expect($telephone->getValidators())->count(1);
$telephone->addValidators(array(new StringLength(array('min' => 5, 'messageMinimum' => 'The telephone is too short')), new Regex(array('pattern' => '/\\+44 [0-9]+ [0-9]+/', 'message' => 'The telephone has an invalid format'))));
expect($telephone->getValidators())->count(3);
//Second element
$address = new Text('address');
$address->addValidator(new PresenceOf(array('message' => 'The address is required')));
expect($address->getValidators())->count(1);
$form = new Form();
$form->add($telephone);
$form->add($address);
expect($form->isValid([]))->false();
$expectedMessages = Group::__set_state(array('_messages' => array(0 => Message::__set_state(array('_type' => 'PresenceOf', '_message' => 'The telephone is required', '_field' => 'telephone', '_code' => 0)), 1 => Message::__set_state(array('_type' => 'TooShort', '_message' => 'The telephone is too short', '_field' => 'telephone', '_code' => 0)), 2 => Message::__set_state(array('_type' => 'Regex', '_message' => 'The telephone has an invalid format', '_field' => 'telephone', '_code' => 0)), 3 => Message::__set_state(array('_type' => 'PresenceOf', '_message' => 'The address is required', '_field' => 'address', '_code' => 0)))));
expect($form->getMessages())->equals($expectedMessages);
expect($form->isValid(array('telephone' => '12345', 'address' => 'hello')))->false();
$expectedMessages = Group::__set_state(array('_messages' => array(0 => Message::__set_state(array('_type' => 'Regex', '_message' => 'The telephone has an invalid format', '_field' => 'telephone', '_code' => 0)))));
expect($form->getMessages())->equals($expectedMessages);
expect($form->isValid(array('telephone' => '+44 124 82122', 'address' => 'hello')))->true();
});
}
示例2: testFormValidator
public function testFormValidator()
{
//First element
$telephone = new Text("telephone");
$telephone->addValidator(new PresenceOf(array('message' => 'The telephone is required')));
$this->assertEquals(count($telephone->getValidators()), 1);
$telephone->addValidators(array(new StringLength(array('min' => 5, 'minimumMessage' => 'The telephone is too short')), new Regex(array('pattern' => '/\\+44 [0-9]+ [0-9]+/', 'message' => 'The telephone has an invalid format'))));
$this->assertEquals(count($telephone->getValidators()), 3);
//Second element
$address = new Text('address');
$address->addValidator(new PresenceOf(array('message' => 'The address is required')));
$this->assertEquals(count($address->getValidators()), 1);
$form = new Form();
$form->add($telephone);
$form->add($address);
$this->assertFalse($form->isValid(array()));
$expectedMessages = Phalcon\Validation\Message\Group::__set_state(array('_messages' => array(0 => Phalcon\Validation\Message::__set_state(array('_type' => 'PresenceOf', '_message' => 'The telephone is required', '_field' => 'telephone', '_code' => 0)), 1 => Phalcon\Validation\Message::__set_state(array('_type' => 'TooShort', '_message' => 'Value of field \'telephone\' is less than the minimum 5 characters', '_field' => 'telephone', '_code' => 0)), 2 => Phalcon\Validation\Message::__set_state(array('_type' => 'Regex', '_message' => 'The telephone has an invalid format', '_field' => 'telephone', '_code' => 0)), 3 => Phalcon\Validation\Message::__set_state(array('_type' => 'PresenceOf', '_message' => 'The address is required', '_field' => 'address', '_code' => 0)))));
$this->assertEquals($form->getMessages(), $expectedMessages);
$this->assertFalse($form->isValid(array('telephone' => '12345', 'address' => 'hello')));
$expectedMessages = Phalcon\Validation\Message\Group::__set_state(array('_messages' => array(0 => Phalcon\Validation\Message::__set_state(array('_type' => 'Regex', '_message' => 'The telephone has an invalid format', '_field' => 'telephone', '_code' => 0)))));
$this->assertEquals($form->getMessages(), $expectedMessages);
$this->assertTrue($form->isValid(array('telephone' => '+44 124 82122', 'address' => 'hello')));
}