本文整理汇总了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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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'))));
}
示例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]'));
}
示例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')));
}
示例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'))));
}
示例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);
}
示例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);
}
示例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;
}
示例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"));
}
示例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'))));
}
示例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'))));
}