当前位置: 首页>>代码示例>>PHP>>正文


PHP Text::getValidators方法代码示例

本文整理汇总了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();
     });
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:25,代码来源:FormTest.php

示例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')));
 }
开发者ID:aisuhua,项目名称:phalcon-php,代码行数:23,代码来源:FormsTest.php


注:本文中的Phalcon\Forms\Element\Text::getValidators方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。