Esempio n. 1
0
 public function initialize()
 {
     $content = new TextArea('content', array('rows' => 35, 'style' => 'display: none', 'spellcheck' => 'false'));
     $content->addValidator(new PresenceOf(array('message' => 'Some content is required')));
     $this->add($content);
     $id = new Hidden('id');
     $id->addValidator(new Regex(array('pattern' => '/[0-9]*/', 'message' => 'The page id can only be numerical')));
     $this->add($id);
 }
Esempio n. 2
0
 /**
  * @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);
     }
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 public function initialize()
 {
     $name = new Text("name");
     $name->setLabel('Name');
     $name->addValidator(new PresenceOf(array('message' => '<strong>Name</strong> is required.')));
     $this->add($name);
     $format = new Select("format", ['CSV' => 'Standard CSV', 'Excel' => 'Micosoft Excel (.xlsx)']);
     $format->setLabel('File format');
     $this->add($format);
     $qry = new TextArea("qry");
     $qry->setLabel('Query');
     $qry->addValidator(new PresenceOf(array('message' => '<strong>Query</strong> is required.')));
     $this->add($qry);
     //$this->setCsrf();
 }
Esempio n. 5
0
 public function initialize()
 {
     $keyMap = $this->getUserKeys();
     $rendererMap = $this->di->get('renderer')->getRendererNameMap();
     $this->add($title = new Text('title'));
     $this->add(new Text('description'));
     $this->add($body = new TextArea('body'));
     $this->add($key = new \Phalcon\Forms\Element\Select('key_id', $keyMap));
     $this->add($format = new \Phalcon\Forms\Element\Select('format', $rendererMap));
     $key->setDefault($this->user->accountKey_id);
     $title->addValidator(new \Phalcon\Validation\Validator\PresenceOf(['message' => 'Title is required']));
     $body->addValidator(new \Phalcon\Validation\Validator\PresenceOf(['message' => 'Content is required']));
     $key->addValidator(new \Phalcon\Validation\Validator\InclusionIn(['message' => 'Encryption key is required', 'domain' => array_keys($keyMap)]));
     $format->addValidator(new \Phalcon\Validation\Validator\InclusionIn(['message' => 'Format is required', 'domain' => array_keys($rendererMap)]));
 }
Esempio n. 6
0
 public static function buildCommentForm(myModel $entity = null, Comments $comment = null)
 {
     if ($comment == null) {
         $form = new Form();
         $form->add(new Submit('Add Comment'));
         if (null != $entity) {
             $form->Url = $entity->getAddCommentFormUrl();
         }
     } else {
         $form = new Form($comment);
         $form->add(new Submit('修改'));
     }
     $content = new TextArea('content');
     $content->addValidator(new PresenceOf(['message' => '评论内容不能为空']));
     //这里也是一个增加验证的地方
     $form->add($content);
     return $form;
 }
Esempio n. 7
0
 public function initialize($entity = null)
 {
     // In edit page the id is hidden
     if (!is_null($entity)) {
         $this->add(new Hidden('id'));
     }
     //Name
     $name = new Text('name', array('placeholder' => t('Name'), 'class' => 'form-control', 'required' => true));
     $name->addValidator(new PresenceOf(array('message' => t('The name is required.'))));
     $this->add($name);
     $slug = new Text('slug', array('placeholder' => t('Slug'), 'class' => 'form-control', 'required' => true));
     $slug->addValidator(new PresenceOf(array('message' => t('The name is required.'))));
     $this->add($slug);
     //description
     $description = new TextArea('description', array('placeholder' => t('Description'), 'class' => 'form-control', 'required' => true));
     $description->addValidator(new PresenceOf(array('message' => t('Description is required.'))));
     $this->add($description);
     // CSRF
     $this->add(new Submit('save', array('class' => 'btn btn-sm btn-info', 'value' => 'Save')));
 }
Esempio n. 8
0
 public function initialize($entity = null, $options = null)
 {
     //In edition the id is hidden
     if (isset($options['edit']) && $options['edit']) {
         $id = new Hidden('id');
     } else {
         $id = new Text('id');
     }
     $this->add($id);
     //$title = new Text('title');//<input type="text" value="" id="username" name="username">
     $title = new Text('title', array('placeholder' => 'Enter title', 'class' => 'span10'));
     $title->setLabel('Title');
     //<label for="username">Username</label>
     $title->addValidators(array(new PresenceOf(array('message' => 'The title is required'))));
     $this->add($title);
     $this->add(new Text('tags', array('placeholder' => 'tags')));
     $content = new TextArea('content', array('placeholder' => ' Enter text ...', 'class' => 'span10', 'rows' => '10', 'cols' => '80'));
     $content->addValidator(new PresenceOf(array('message' => 'The content is required')));
     $this->add($content);
     $categories = new Select('categoriesId', Categories::find(), array('using' => array('id', 'name'), 'useEmpty' => true, 'emptyText' => '----', 'emptyValue' => ''));
     $this->add($categories);
 }
Esempio n. 9
0
 public function initialize($entity = null, $options = null)
 {
     //In edition the id is hidden
     if (isset($options['edit']) && $options['edit']) {
         $id = new Hidden('id');
     } else {
         $id = new Text('id');
     }
     $this->add($id);
     $fileCaption = new Text('fileCaption', array('placeholder' => $this->request->getPost('fileCaption')));
     $fileCaption->setLabel(_('Caption'));
     $fileCaption->addValidators(array(new PresenceOf(array('message' => _('Document caption not null')))));
     $this->add($fileCaption);
     $fileData = new File('fileData');
     $fileData->setLabel('Document upload');
     /*$fileData->addValidators(array(
     			new PresenceOf(array(
     				'message' =>_('Document file required')
     				))
     		));*/
     $this->add($fileData);
     //render if action is edit
     $fileDataEdit = new File('fileDataEdit');
     $fileDataEdit->setLabel('Document upload');
     /*$fileData->addValidators(array(
     			new PresenceOf(array(
     				'message' =>_('Document file required')
     				))
     		));*/
     $this->add($fileDataEdit);
     $categories = new Select('categoriesId', Categories::find(), array('using' => array('id', 'name'), 'useEmpty' => true, 'emptyText' => '----', 'emptyValue' => ''));
     $categories->setLabel('Categories');
     $this->add($categories);
     $description = new TextArea('description', array('placeholder' => ' Enter text ...', 'class' => 'span8', 'rows' => '6'));
     $description->addValidator(new PresenceOf(array('message' => _('The description is required'))));
     $description->setLabel('Description');
     $this->add($description);
     $this->add(new Text('q', array('placeholder' => $this->request->getPost('q', 'striptags'))));
 }
Esempio n. 10
0
 public function initialize($entity = null)
 {
     // In edit page the id is hidden
     if (!is_null($entity)) {
         $this->add(new Hidden('id'));
     }
     $content = new TextArea('content', ['placeholder' => t('Use comments to ask for more information or suggest improvements. Avoid comments like "+1" or "thanks".')]);
     $content->addValidator(new PresenceOf(['message' => t('The content is required')]));
     $this->add($content);
     $this->add(new Hidden('objectId'));
     $this->add(new Hidden('object'));
     $csrf = new Hidden('csrf');
     //@todo fix later
     /**$csrf->addValidator(
            new Identical(array(
                'value'   => $this->security->getSessionToken(),
                'message' => t('CSRF validation failed')
            ))
        );*/
     $this->add($csrf);
     //Submit
     $this->add(new Submit('postComment', ['value' => t('Add comment'), 'class' => 'btn btn-sm btn-info']));
 }
Esempio n. 11
0
 public function initialize($entity = null)
 {
     //name
     $name = new Text('name', ['placeholder' => t('You name'), 'class' => 'form-control', 'required' => true]);
     $name->addValidator(new PresenceOf(['message' => t('The name is required.')]));
     $this->add($name);
     //email
     $email = new Text('email', ['placeholder' => t('You email'), 'class' => 'form-control', 'required' => true]);
     $email->addValidator(new PresenceOf(['message' => t('The email is required.')]));
     $this->add($email);
     //subject
     $subject = new Text('subject', ['placeholder' => t('You subject'), 'class' => 'form-control', 'required' => true]);
     $subject->addValidator(new PresenceOf(['message' => t('The subject is required.')]));
     $this->add($subject);
     //description
     $description = new TextArea('description', ['placeholder' => t('Please enter you messages'), 'class' => 'form-control', 'rows' => '5', 'required' => true]);
     $description->addValidator(new PresenceOf(['message' => t('Description is required.')]));
     $this->add($description);
     // CSRF
     $csrf = new Hidden('csrf');
     $csrf->addValidator(new Identical(['value' => $this->security->getSessionToken(), 'message' => 'CSRF validation failed']));
     $this->add($csrf);
     $this->add(new Submit('submit', ['class' => 'btn btn-sm btn-info', 'value' => 'Submit']));
 }
Esempio n. 12
0
 /**
  * Build SEOForm
  *
  * @param mixed $data
  * @return $this
  */
 protected function buildSEOForm($data = null)
 {
     if ($data != null) {
         $metadataArray = json_decode($data->metadata, true);
         $robots = explode(',', $metadataArray['robots']);
         $data->zcms_seo_title = $metadataArray['title'];
         $data->redirect_301 = $metadataArray['redirect_301'];
         $data->zcms_meta_robot_index = isset($robots[0]) ? $robots[0] : null;
         $data->zcms_meta_robot_follow = isset($robots[1]) ? $robots[1] : null;
     }
     //Title
     $seo_title = new Text('zcms_seo_title');
     $seo_title->addValidator(new StringLength(['min' => 0, 'max' => 255]));
     $this->add($seo_title);
     //Meta description
     $meta_desc = new TextArea('metadesc', ['rows' => 4]);
     $meta_desc->addValidator(new StringLength(['min' => 0, 'max' => 255]));
     $this->add($meta_desc);
     //Meta keywords
     $meta_key = new TextArea('metakey', ['rows' => 4]);
     $meta_key->addValidator(new StringLength(['min' => 0, 'max' => 255]));
     $this->add($meta_key);
     //Meta Robots Index:
     $meta_robot_index = new Select('zcms_meta_robot_index', ['index' => 'Index', 'noindex' => 'NoIndex']);
     $meta_robot_index->addValidator(new InclusionIn(['domain' => ['index', 'noindex']]));
     $this->add($meta_robot_index);
     //Meta Robots Follow
     $meta_robot_follow = new Select('zcms_meta_robot_follow', ['follow' => 'Follow', 'nofollow' => 'NoFollow']);
     $meta_robot_follow->addValidator(new InclusionIn(['domain' => ['follow', 'nofollow']]));
     $this->add($meta_robot_follow);
     //Meta robot advance
     $meta_robot_advance = new Select('zcms_meta_robot_advance', ['none' => 'None', 'noodp' => 'NO ODP', 'noydir' => 'NO YDIR', 'noimageindex' => 'No Image Index', 'noarchive' => 'No Archive', 'nosnippet' => 'No Snippet'], ['multiple' => 'multiple', 'name' => 'zcms_meta_robot_advance[]']);
     //       $meta_robot_advance->addValidator(new InclusionIn([
     //           'domain' => ['none', 'noodp', 'noydir', 'noimageindex', 'noarchive', 'nosnippet']
     //       ]));
     $this->add($meta_robot_advance);
     //Redirect 301
     $redirect301 = new Text('zcms_redirect_301');
     $this->add($redirect301);
     //Add metadata
     $metadata = new TextArea('metadata');
     $this->add($metadata);
     return $this;
 }