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


PHP Text::addValidator方法代码示例

本文整理汇总了PHP中Phalcon\Forms\Element\Text::addValidator方法的典型用法代码示例。如果您正苦于以下问题:PHP Text::addValidator方法的具体用法?PHP Text::addValidator怎么用?PHP Text::addValidator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phalcon\Forms\Element\Text的用法示例。


在下文中一共展示了Text::addValidator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initialize

 /**
  * @param Phalcon\Mvc\ModelInstance $entity
  * @param array $options
  */
 public function initialize($entity = null, $options = null)
 {
     if (!isset($options['edit']) && !isset($options['create'])) {
         $id = new Text('id');
         $id->setLabel('Id');
         $this->add($id);
     }
     $category = new Select('categoriesId', Categories::find(), array('using' => array('id', 'name'), 'useEmpty' => true, 'emptyText' => '...'));
     $category->setLabel('Category');
     $category->addValidator(new PresenceOf(array('message' => 'Category is mandatory')));
     $category->setUserOption('searcheable', true);
     $category->setUserOption('browseable', true);
     $category->setUserOption('relation', 'category');
     $this->add($category);
     $icon = new Text('icon', array('placeholder' => 'Enter a css-icon class name'));
     $icon->setLabel('Icon');
     $icon->addValidator(new PresenceOf(array('message' => 'Icon is mandatory')));
     $this->add($icon);
     $code = new Text('code', array('maxlength' => 10));
     $code->setLabel('Code');
     $code->setUserOption('searcheable', true);
     $code->setUserOption('browseable', true);
     $code->addValidator(new PresenceOf(array('message' => 'Code is mandatory')));
     $this->add($code);
     $name = new Text('name', array('maxlength' => 64));
     $name->setLabel('Name');
     $name->setUserOption('searcheable', true);
     $name->setUserOption('browseable', true);
     $name->addValidator(new PresenceOf(array('message' => 'Name is mandatory')));
     $this->add($name);
     $description = new TextArea('description');
     $description->setLabel('Description');
     $description->addValidator(new PresenceOf(array('message' => 'Description is mandatory')));
     $this->add($description);
     $price = new Text('price');
     $price->setLabel('Price');
     $price->setUserOption('searcheable', true);
     $price->setUserOption('browseable', true);
     $price->addValidator(new PresenceOf(array('message' => 'Price is mandatory')));
     $price->addValidator(new Numericality(array('message' => 'Price must be a number')));
     $this->add($price);
     $stock = new Text('stock');
     $stock->setLabel('Stock');
     $stock->setUserOption('browseable', true);
     $stock->addValidator(new PresenceOf(array('message' => 'Current stock is mandatory')));
     $stock->addValidator(new Numericality(array('message' => 'Current stock must be a number')));
     $this->add($stock);
     if (isset($options['edit'])) {
         $createdAt = new Date('created', array('readonly' => 'readonly'));
         $createdAt->setLabel('Created At');
         if ($entity->createdAt) {
             $entity->created = date('Y-m-d', $entity->createdAt);
         }
         $this->add($createdAt);
     }
 }
开发者ID:riquedesimone,项目名称:biko,代码行数:60,代码来源:ProductsForm.php

示例2: initialize

 public function initialize()
 {
     $content = new TextArea('content', array('rows' => 35, 'style' => 'display: none;', 'placeholder' => 'Some Markdown text'));
     $content->addValidator(new PresenceOf(array('message' => 'Some content is required')));
     $this->add($content);
     $title = new Text('title', array('placeholder' => 'Title (CamelCase only)', 'autofocus' => true));
     $title->addValidator(new PresenceOf(array('message' => 'A title is required')));
     $title->addValidator(new Regex(array('pattern' => '/[A-Z][a-zA-Z]*/', 'message' => 'Only CamelCase or single word titles are allowed')));
     $this->add($title);
 }
开发者ID:niden,项目名称:kolibri,代码行数:10,代码来源:Create.php

示例3: initialize

 public function initialize()
 {
     $userName = new Text('userName');
     $userName->addValidator(new PresenceOf(array('message' => 'User name is required')));
     $password = new Password('password');
     $password->addValidator(new PresenceOf(array('message' => 'Password is required')));
     $email = new Text('email');
     $email->addValidator(new PresenceOf(array('message' => 'Email is required')));
     $email->addValidator(new Email(array('message' => 'Email is not valid')));
     $this->add($userName);
     $this->add($password);
     $this->add($email);
 }
开发者ID:proskills,项目名称:literal-literature,代码行数:13,代码来源:SignUpForm.php

示例4: initialize

 public function initialize()
 {
     $id = new Text("id");
     $id->addValidator(new PresenceOf(array('message' => 'ID can not be empty.')));
     $id->addValidator(new Regex(array('pattern' => '/[a-z0-9_-]+/i', 'message' => 'В ID must be a-z 0-9 _ -')));
     $id->setLabel('ID');
     $title = new Text("title");
     $title->setLabel('Title');
     $html = new TextArea("html");
     $html->setLabel('HTML');
     $this->add($id);
     $this->add($title);
     $this->add($html);
 }
开发者ID:devsnippet,项目名称:yona-cms,代码行数:14,代码来源:WidgetForm.php

示例5: initialize

 public function initialize()
 {
     $name = new Text("name");
     $name->setLabel('Name');
     $name->addValidator(new PresenceOf(['message' => '<strong>Name</strong> is required.']));
     $this->add($name);
     $adapter = new Select("adapter", ['Mysql' => 'MySQL']);
     $adapter->setLabel('DB type');
     $this->add($adapter);
     $host = new Text("host");
     $host->setLabel('DB host');
     $host->addValidator(new PresenceOf(['message' => '<strong>DB host</strong> is required.']));
     $this->add($host);
     $user = new Text("username");
     $user->setLabel('DB user');
     $user->addValidator(new PresenceOf(array('message' => '<strong>DB user</strong> is required.')));
     $this->add($user);
     $pass = new Text("password");
     $pass->setLabel('DB pass');
     $this->add($pass);
     $dbname = new Text("dbname");
     $dbname->setLabel('DB name');
     $dbname->addValidator(new PresenceOf(array('message' => '<strong>DB name</strong> is required.')));
     $this->add($dbname);
     //$this->setCsrf();
 }
开发者ID:mpetcu,项目名称:lime-juice,代码行数:26,代码来源:DbForm.php

示例6: initialize

 public function initialize()
 {
     $login = new Text('login');
     $login->addValidator(new PresenceOf(array('message' => $this->helper->translate('Login is required'))));
     $password = new Password('password');
     $password->addValidator(new PresenceOf(array('message' => $this->helper->translate('Password is required'))));
 }
开发者ID:101010111100,项目名称:yona-cms,代码行数:7,代码来源:LoginForm.php

示例7: testArrayedValues

 public function testArrayedValues()
 {
     $model = new FakeModel();
     $values = array('integer' => '3 14', 'test1' => array(2 => 'foo', 3 => 'bar'), 'test2' => array('en' => 'baz', 'nl' => 123.4), 'test3' => array(array(0 => 'doubleArrayed', 1 => array(0 => 'tripleArrayed'))), 'not_in_form' => array('some_value'));
     $form = new Form();
     $text = new Text('integer');
     $text->addFilter('int');
     $form->add($text);
     $form->add(new Text('test1[]'));
     $form->add(new Text('test1[]'));
     $text = new Text('test2[en]');
     $text->addValidator(new PresenceOf());
     $form->add($text);
     $text = new Text('test2[nl]');
     $text->addFilter('int');
     $form->add($text);
     $form->add(new Text('test3[0][]'));
     $form->add(new Text('test3[0][1][]'));
     $form->bind($values, $model);
     $this->assertTrue($form->isValid());
     $this->assertTrue(!isset($model->not_in_form));
     $this->assertEquals('3 14', $form->getValue('integer'));
     $this->assertEquals(314, $model->integer);
     $this->assertEquals($model->test1[0], $form->getValue('test1[2]'));
     $this->assertEquals($model->test1[1], $form->getValue('test1[3]'));
     $this->assertNull($form->getValue('test1[]'));
     $this->assertNull($form->getValue('test1[1]'));
     $this->assertEquals($model->test2['en'], $form->getValue('test2[en]'));
     $this->assertEquals(123.4, $form->getValue('test2[nl]'));
     $this->assertEquals(1234, $model->test2['nl']);
     $this->assertNull($form->getValue('test2[en][notexsiting]'));
     $this->assertEquals($model->test3[0][0], $form->getValue('test3[0][0]'));
     $this->assertEquals($model->test3[0][1][0], $form->getValue('test3[0][1][0]'));
 }
开发者ID:vegas-cmf,项目名称:forms,代码行数:34,代码来源:FormTest.php

示例8: initialize

 public function initialize()
 {
     //username
     $username = new Text('login');
     $username->setLabel('Login');
     $username->addValidator(new PresenceOf(array("message" => "Login required")));
     $username->setAttributes(array('id' => 'login-username', 'class' => 'form-control', 'placeholder' => 'username'));
     $this->add($username);
     //password
     $password = new Password('password');
     $password->setLabel('Password');
     $password->addValidator(new PresenceOf(array("message" => "Password required")));
     $password->setAttributes(array('id' => 'login-password', 'class' => 'form-control', 'placeholder' => 'password'));
     $password->clear();
     $this->add($password);
     //remember me
     $remember = new Check('remember', array("value" => '1', "id" => "login-remember"));
     $remember->setLabel('Remember me');
     $this->add($remember);
     //CSRF
     $csrf = new Hidden('csrf');
     $csrf->addValidator(new Identical([$this->security->checkToken() => true, 'message' => 'This request was aborted because it appears to be forged']));
     $this->add($csrf);
     //Submit
     $this->add(new Submit('Sign In', array('class' => 'btn btn-success', 'id' => 'btn-login')));
 }
开发者ID:netassist-ua,项目名称:netgraphz2-gpl,代码行数:26,代码来源:LoginForm.php

示例9: initialize

 public function initialize($entity = null)
 {
     // In edit page the id is hidden
     if (!is_null($entity)) {
         $this->add(new Hidden('id'));
     }
     //title
     $title = new Text('title', array('placeholder' => t('title'), 'class' => 'form-control', 'required' => true));
     $title->addValidator(new PresenceOf(array('message' => t('The title is required.'))));
     $this->add($title);
     //title
     $link = new Text('link', array('class' => 'form-control', 'required' => true));
     $link->addValidator(new PresenceOf(array('message' => t('The link is required.'))));
     $this->add($link);
     //content
     $content = new Textarea('content', array('placeholder' => t('Adding information for link your submit!'), 'class' => 'wmd-input', 'id' => 'wmd-input', 'required' => true, 'rows' => 10));
     $content->addValidator(new PresenceOf(array('message' => t('content is required.'))));
     $this->add($content);
     $this->add(new Hidden('object'));
     // To compare the post is question or tip
     $this->add(new Hidden('type'));
     // CSRF
     $csrf = new Hidden('csrf');
     $csrf->addValidator(new Identical(array('value' => $this->security->getSessionToken(), 'message' => 'CSRF validation failed')));
     $this->add($csrf);
     $this->add(new Submit('save', array('class' => 'btn btn-sm btn-success', 'value' => t('Submit Link'))));
 }
开发者ID:gitter-badger,项目名称:phanbook,代码行数:27,代码来源:HackernewForm.php

示例10: initialize

 public function initialize($model = null)
 {
     $system = new \Modules\Library\System();
     // Main tab
     $title = new Text("title");
     $title->addValidator(new PresenceOf());
     $this->add($title);
     $this->add(new Text("code"));
     $status = new Select('status', array('0' => 'Không', '1' => 'Có'));
     $status->setDefault('1');
     $this->add($status);
     // $this->add(new Select('status', array('0'=>'Không', '1'=>'Có')));
     $this->add(new Select('featured', array('0' => 'Không', '1' => 'Có')));
     $this->add(new Text("image"));
     $this->add(new TextArea("description"));
     $this->add(new TextArea("content"));
     // Config tab
     $this->add(new Text("link"));
     $this->add(new Select('url_target', array('normal' => 'Bình thường', '_blank' => 'Mở trang mới')));
     $this->add(new Text("published", array('data-format' => 'yyyy-MM-dd hh:mm:ss', 'value' => date('d-m-Y H:i:s'))));
     $this->add(new Text("position"));
     // SEO tab
     $this->add(new Text("seo_title"));
     $this->add(new TextArea("metadata"));
     $this->add(new TextArea("keyword"));
     $result = \Modules\Backend\Models\News_category::find();
     $system = new \Modules\Library\System();
     $result = $system->convert_object_to_array($result);
     $data = null;
     $system->recursive($result, 0, 1, $data);
     $record = $system->getListTreeCategory($data, "title");
     $category_id = new Select('category_id', $record);
     $this->add($category_id);
 }
开发者ID:quyquoc,项目名称:rmt-studio.com,代码行数:34,代码来源:News_article.php

示例11: initialize

 /**
  * Init user form
  *
  * @param \ZCMS\Core\Models\Users $data
  */
 public function initialize($data = null)
 {
     //Add first name
     $firstName = new Text('first_name', ['maxlength' => '32']);
     $firstName->addValidator(new PresenceOf());
     $this->add($firstName);
     //Add last name
     $lastName = new Text('last_name', ['maxlength' => '32']);
     $lastName->addValidator(new PresenceOf());
     $this->add($lastName);
     //Add email
     if ($data = null) {
         $email = new Email('email', ['maxlength' => '128', 'readonly' => 'readonly']);
     } else {
         $email = new Email('email', ['maxlength' => '128']);
     }
     $this->add($email);
     //Add active
     $is_active = new Select('is_active', ['1' => __('gb_yes'), '0' => __('gb_no')]);
     $this->add($is_active);
     //Add password confirmation
     $password_confirmation = new Password('password_confirmation', ['maxlength' => '32']);
     $password_confirmation->addValidator(new StringLength(['min' => 6]));
     $this->add($password_confirmation);
     //Add password
     $password = new Password('password', ['maxlength' => '32']);
     $password->addValidator(new StringLength(['min' => 6]));
     $password->addValidator(new Confirmation(['message' => 'm_system_user_message_password_does_not_match_confirmation', 'with' => 'password_confirmation']));
     $this->add($password);
     //Add role
     $dbRoles = UserRoles::find(['conditions' => 'is_super_admin = 0', 'order' => 'is_default DESC']);
     $role = new Select('role_id', $dbRoles, ['using' => ['role_id', 'name']]);
     $role->addValidator(new InclusionIn(['message' => 'm_system_user_message_please_choose_role', 'domain' => array_column($dbRoles->toArray(), 'role_id')]));
     $this->add($role);
 }
开发者ID:kimthangatm,项目名称:zcms,代码行数:40,代码来源:UserForm.php

示例12: attachUsername

 /**
  * attach the username field with validators
  */
 protected function attachUsername()
 {
     $username = new Text('username');
     $username->addValidator(new PresenceOf(['message' => 'The username is required']));
     $this->username = $username;
     $this->formElements['username'] = $username;
 }
开发者ID:adrianeavaz,项目名称:manager.io,代码行数:10,代码来源:LoginBase.php

示例13: initialize

 public function initialize($model, $menu_id = null)
 {
     $system = new \Modules\Library\System();
     // Main tab
     $name = new Text("name");
     $name->addValidator(new PresenceOf(array('message' => 'name')));
     $this->add($name);
     $this->add(new Text("code"));
     $link = new Text("link");
     $link->addValidator(new PresenceOf(array('message' => 'link')));
     $this->add($link);
     // parents menu item
     $result = \Modules\Backend\Models\Menu_item::findByMenu_id($menu_id);
     $result = $system->convert_object_to_array($result);
     $data = null;
     $system->recursive($result, 0, 1, $data);
     $data = $system->getListTreeCategory($data, 'name');
     $parents = new Select('parents', $data);
     $this->add($parents);
     $tbl_menu = \Modules\Backend\Models\Menu::find();
     $menu = new Select('menu_id', $tbl_menu, array('using' => array('id', 'name')));
     $menu->setDefault($menu_id);
     $this->add($menu);
     $status = new Select('status', array('0' => 'Không', '1' => 'Có'));
     $status->setDefault('1');
     $this->add($status);
     $target = new Select('target', array('0' => 'Bình thường', '1' => 'Mở tab mới'));
     $this->add($target);
     $this->add(new Text("image"));
     $this->add(new Text("position"));
 }
开发者ID:quyquoc,项目名称:rmt-studio.com,代码行数:31,代码来源:Menu_item.php

示例14: initialize

 public function initialize($entity = null)
 {
     // In edit page the id is hidden
     if (!is_null($entity)) {
         $this->add(new Hidden('id'));
     }
     //title
     $title = new Text('title', array('placeholder' => t('Title'), 'class' => 'form-control', 'required' => true));
     $title->addValidator(new PresenceOf(array('message' => t('The title is required.'))));
     $this->add($title);
     // In edit page the id is hidden
     if (!empty($entity)) {
         $checked = null;
         $this->add(new Radio('locked', ['value' => 'Y', 'checked' => $checked, 'name' => 'locked']));
         if ($entity->getLocked() == 'N') {
             $checked = 'checked';
         }
         $this->add(new Radio('unLocked', ['value' => 'N', 'checked' => $checked, 'name' => 'locked']));
     } else {
         $this->add(new Radio('locked', ['value' => 'Y', 'name' => 'locked']));
         $this->add(new Radio('unLocked', ['value' => 'N', 'name' => 'locked']));
     }
     //content
     $content = new Textarea('content', array('placeholder' => t('Please be sure to answer the question. Provide details and share your research!'), 'class' => 'wmd-input', 'id' => 'wmd-input', 'required' => true, 'rows' => 10));
     $content->addValidator(new PresenceOf(array('message' => t('content is required.'))));
     $this->add($content);
     $this->add(new Hidden('object'));
     // To compare the post is question or tip
     $this->add(new Hidden('type'));
     // CSRF
     $csrf = new Hidden('csrf');
     $this->add($csrf);
     $this->add(new Submit('save', array('class' => 'btn btn-sm btn-success', 'value' => t('Submit Post'))));
 }
开发者ID:gitter-badger,项目名称:phanbook,代码行数:34,代码来源:PostsForm.php

示例15: initialize

 public function initialize($entity = null)
 {
     // In edit page the id is hidden
     if (!is_null($entity)) {
         $this->add(new Hidden('id'));
     }
     //title
     $title = new Text('title', array('placeholder' => t('title'), 'class' => 'form-control', 'required' => true));
     $title->addValidator(new PresenceOf(array('message' => t('The title is required.'))));
     $this->add($title);
     $tags = new Hidden('tags', array('required' => true));
     $tags->addValidator(new PresenceOf(array('message' => t('The title is required.'))));
     $this->add($tags);
     //content
     $content = new Textarea('content', array('placeholder' => t('Please be sure to answer the question. Provide details and share your research!'), 'class' => 'wmd-input', 'id' => 'wmd-input', 'required' => true, 'rows' => 10));
     $content->addValidator(new PresenceOf(array('message' => t('content is required.'))));
     $this->add($content);
     $this->add(new Hidden('object'));
     // To compare the post is question or tip
     $this->add(new Hidden('type'));
     // CSRF
     $csrf = new Hidden('csrf');
     $csrf->addValidator(new Identical(array('value' => $this->security->getSessionToken(), 'message' => 'CSRF validation failed')));
     $this->add($csrf);
     $this->add(new Submit('save', array('class' => 'btn btn-sm btn-success', 'value' => t('Submit Post'))));
 }
开发者ID:kjmtrue,项目名称:phanbook,代码行数:26,代码来源:QuestionsForm.php


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