function editAction($modules_id, $system_id)
 {
     $modules = Modules::findFirstById($modules_id);
     $system = Systems::findFirstById($system_id);
     $form = new Form($modules);
     $form->add(new Text("name"));
     $form->add(new TextArea("description"));
     $form->add(new Hidden("system_id"));
     $form->add(new Hidden("id"));
     #	$form = new ModulesForm;
     $this->view->modules = $modules;
     $this->view->system = $system;
     $this->view->page = 'Modules';
     $this->view->form = $form;
     if ($this->request->isPost()) {
         $name = $this->request->getPost('name');
         $description = $this->request->getPost('description');
         $system_id = $this->request->getPost('system_id');
         $modules_id = $this->request->getPost('id');
         $modules = Modules::find($modules_id);
         if ($modules->update($this->request->getPost()) == false) {
             foreach ($modules->getMessages() as $message) {
                 $this->flash->error((string) $message);
             }
         } else {
             $this->flash->success('Edit Modules Success');
             $this->response->redirect('modules/system/' . $system_id);
         }
     }
 }
Example #2
0
 public static function buildLoginForm()
 {
     $form = new \Phalcon\Forms\Form();
     $form->add(new \Phalcon\Forms\Element\Text('email'));
     $form->add(new \Phalcon\Forms\Element\Password('password'));
     $form->add(new \Phalcon\Forms\Element\Check('remember'));
     $form->add(new \Phalcon\Forms\Element\Submit('Login'));
     return $form;
 }
Example #3
0
 private function buildCommentForm(Tags $tag, Comments $comment = null)
 {
     if ($comment) {
         $form = new Form($comment);
         $form->Url = "tags/" . $tag->id . "/comments/" . $comment->id . "/edit";
     } else {
         $form = new Form();
         $form->Url = "tags/" . $tag->id . "/addComment";
     }
     $form->add(new \Phalcon\Forms\Element\TextArea('content'));
     $form->add(new \Phalcon\Forms\Element\Submit('Add Comment'));
     return $form;
 }
 protected function getForm($entity = null, $edit = false)
 {
     $form = new Form($entity);
     if (!$edit) {
         $form->add(new Text("id", array("size" => 10, "maxlength" => 10)));
     } else {
         $form->add(new Hidden("id"));
     }
     $form->add(new Text("name", array("size" => 24, "maxlength" => 50)));
     $form->add(new Text("limit", array("size" => 10, "maxlength" => 50)));
     $form->add(new Textarea("remark", array("cols" => 14, "rows" => 5, "maxlength" => 250)));
     return $form;
 }
Example #5
0
 public static function buildFormFromModel(myModel $object)
 {
     $form = new Form($object);
     $fields = [];
     foreach ($object->columnMap() as $column) {
         if (!in_array($column, ['created_at', 'updated_at', 'id'])) {
             $form->add(new \Phalcon\Forms\Element\Text($column));
             $fields[] = $column;
         }
     }
     $form->fields = $fields;
     $form->add(new \Phalcon\Forms\Element\Submit('修改'));
     return $form;
 }
Example #6
0
 /**
  * Adds an element to the form
  * @param \Phalcon\Forms\ElementInterface $element
  */
 public function add($element, $postion = null, $type = null)
 {
     $type = strtolower(current(array_reverse(explode("\\", get_class($element)))));
     parent::add($element, $postion, $type);
     if ($type == "hidden") {
         $this->_hiddenElements[] = $element;
     } else {
         $this->_inputElements[] = [$element, $this->_currentFieldset];
     }
 }
 public function editAction()
 {
     $post = Post::findFirst($this->dispatcher->getParam("id"));
     $data = array();
     foreach ($posts as $post) {
         $item = array();
         $item['id'] = $post->id;
         $item['title'] = $post->title;
         $item['content'] = $post->content;
         $item['status'] = $post->post_status;
         $item['post_modified'] = $post->post_modified;
         foreach ($post->category as $category) {
             $item['category'] = $category->name;
         }
         $data[] = $item;
     }
     $this->view->setVar("post", $post);
     $form = new Form();
     $form->add(new Text("name"));
     $form->add(new Text("telephone"));
     \PhalconDebug::addMessage($form->render("name"), 'Info');
 }
Example #8
0
 protected function buildFormFromModel(myModel $model)
 {
     if ($model->id) {
         $form = new Form($model);
     } else {
         $form = new Form();
     }
     $fields = [];
     foreach ($model->columnMap() as $column) {
         if (!in_array($column, ['created_at', 'updated_at', 'id', 'password', 'remember_token'])) {
             $form->add(new \Phalcon\Forms\Element\Text($column));
             $fields[] = $column;
         }
     }
     $form->fields = $fields;
     if ($model->id) {
         $form->add(new \Phalcon\Forms\Element\Submit('修改'));
     } else {
         $form->add(new \Phalcon\Forms\Element\Submit('增加'));
     }
     return $form;
 }
Example #9
0
 public static function buildFormFromModel(\Phalcon\Mvc\Model $model, array $extraFields = null)
 {
     if ($model->id) {
         $form = new Form($model);
     } else {
         $form = new Form();
     }
     $fields = [];
     foreach ($model->columnMap() as $column) {
         $metaDataTypes = $model->getModelsMetaData()->getDataTypes($model);
         if (!in_array($column, ['created_at', 'updated_at', 'id', 'password', 'remember_token'])) {
             if ($metaDataTypes[$column] != 6) {
                 $form->add(new Text($column));
             } else {
                 $form->add(new TextArea($column));
             }
             $fields[] = $column;
         }
     }
     if (null != $extraFields) {
         foreach ($extraFields as $column) {
             if (in_array($column, $model->columnMap())) {
                 continue;
             }
             $form->add(new Text($column));
             $fields[] = $column;
         }
     }
     $form->fields = $fields;
     if ($model->id) {
         $form->add(new Submit('修改'));
     } else {
         $form->add(new Submit('增加'));
     }
     return $form;
 }
Example #10
0
 /**
  * Adds an element to the form, if element has DecoratedInterface, injects DI
  *
  * @param \Phalcon\Forms\ElementInterface $element
  * @param string $postion
  * @param bool $type If $type is TRUE, the element wile add before $postion, else is after
  * @return \Phalcon\Forms\Form
  */
 public function add(ElementInterface $element, $postion = null, $type = null)
 {
     if ($element instanceof Decorator\DecoratedInterface && $element->getDecorator() instanceof DecoratorInterface) {
         $element->getDecorator()->setDI($this->di);
     }
     $reflectionClass = new \ReflectionClass($element);
     $elementType = strtolower(str_replace($reflectionClass->getNamespaceName() . '\\', '', $reflectionClass->getName()));
     $element->setUserOption('_type', $elementType);
     // hax even when $postion and $type are null by default, call parent::add($element, $postion, $type)
     // causes exception : Array position does not exist
     if (!is_null($postion) || !is_null($type)) {
         return parent::add($element, $postion, $type);
     } else {
         return parent::add($element);
     }
 }
Example #11
0
 /**
  * Add range number element
  *
  * @param string $name
  * @param array $attributes
  */
 public function addNumberRangeElement($name, $attributes)
 {
     if (!isset($attributes['class'])) {
         $attributes['class'] = 'form-control input-sm zcms-form-filter';
     } else {
         $attributes['class'] .= ' form-control input-sm zcms-form-filter';
     }
     //Add placeholder
     $attributes['placeholder'] = __('gb_number_from');
     $attributes['value'] = $attributes['value_from'];
     $elementPriceFrom = new Text($name . '_from', $attributes);
     //Add placeholder
     $attributes['placeholder'] = __('gb_number_to');
     $attributes['value'] = $attributes['value_to'];
     $elementPriceTo = new Text($name . '_to', $attributes);
     $this->_form->add($elementPriceFrom);
     $this->_form->add($elementPriceTo);
 }
Example #12
0
 protected function getForm($entity = null, $edit = false)
 {
     $form = new Form($entity);
     if (!$edit) {
         $form->add(new Text("id", array("size" => 10, "maxlength" => 10)));
     } else {
         $form->add(new Hidden("id"));
     }
     $form->add(new Text("name", array("size" => 24, "maxlength" => 70)));
     $form->add(new Text("telephone", array("size" => 10, "maxlength" => 30)));
     $form->add(new Text("address", array("size" => 14, "maxlength" => 40)));
     $form->add(new Text("city", array("size" => 14, "maxlength" => 40)));
     return $form;
 }
 public static function generate($opcoes = array())
 {
     $form = new Form();
     //Numero do cartão
     foreach (self::rules() as $key => $value) {
         if ($value['type'] == 'text') {
             $chave = new Text("pagamento[{$key}]");
         } else {
             if ($value['type'] == 'hidden') {
                 $chave = new Hidden("pagamento[{$key}]");
             } else {
                 $chave = new Select("pagamento[{$key}]", array('emptyText' => 'Parcelas', 'emptyValue' => ''));
             }
         }
         foreach ($value['attributos'] as $k => $v) {
             $chave->setAttribute($k, $v);
         }
         $form->add($chave);
     }
     return $form;
 }
Example #14
0
 /**
  * @issue 706
  */
 public function testIssue706()
 {
     $this->specify("Form field positions don't work", function () {
         $form = new Form();
         $form->add(new Text("name"));
         $form->add(new Text("before"), "name", true);
         $form->add(new Text("after"), "name");
         $data = ["before", "name", "after"];
         $result = [];
         foreach ($form as $element) {
             $result[] = $element->getName();
         }
         expect($result)->equals($data);
     });
 }
Example #15
0
 /**
  * Tests clearing the Form Elements by using Form::bind
  *
  * @issue  11978
  * @author Serghei Iakovlev <*****@*****.**>
  * @since  2016-10-01
  * @param  IntegrationTester $I
  */
 public function clearFormElementsByUsingFormBind(IntegrationTester $I)
 {
     $name = new Text('sel_name');
     $text = new Text('sel_text');
     $form = new Form();
     $form->add($name)->add($text);
     $entity = new MvcModel();
     $I->assertNull(Tag::getValue('sel_name'));
     $I->assertNull($form->getValue('sel_name'));
     $I->assertNull($form->get('sel_name')->getValue());
     $I->assertNull($name->getValue());
     Tag::setDefault('sel_name', 'Please specify name');
     $_POST = ['sel_name' => 'Some Name', 'sel_text' => 'Some Text'];
     $form->bind($_POST, $entity);
     $I->assertEquals('Some Name', $entity->getName());
     $I->assertEquals('Some Text', $entity->getText());
     $I->assertEquals('Some Name', $form->getValue('sel_name'));
     $I->assertEquals('Some Name', $form->get('sel_name')->getValue());
     $I->assertEquals('Some Name', $name->getValue());
     $I->assertEquals('Some Text', $form->getValue('sel_text'));
     $I->assertEquals('Some Text', $form->get('sel_text')->getValue());
     $I->assertEquals('Some Text', $text->getValue());
     $form->clear(['sel_name']);
     $I->assertNull(Tag::getValue('sel_name'));
     $I->assertNull($form->getValue('sel_name'));
     $I->assertNull($form->get('sel_name')->getValue());
     $I->assertNull($name->getValue());
     $I->assertEquals('Some Text', $form->getValue('sel_text'));
     $I->assertEquals('Some Text', $form->get('sel_text')->getValue());
     $I->assertEquals('Some Text', $text->getValue());
     $form->clear(['non_existent', 'another_filed']);
     $I->assertEquals('Some Text', $form->getValue('sel_text'));
     $I->assertEquals('Some Text', $form->get('sel_text')->getValue());
     $I->assertEquals('Some Text', $text->getValue());
     $form->clear();
     $I->assertNull(Tag::getValue('sel_text'));
     $I->assertNull($form->getValue('sel_text'));
     $I->assertNull($form->get('sel_text')->getValue());
     $I->assertNull($text->getValue());
     $I->assertEquals('Some Name', $entity->getName());
     $I->assertEquals('Some Text', $entity->getText());
     $I->assertEquals(['sel_name' => 'Some Name', 'sel_text' => 'Some Text'], $_POST);
 }
Example #16
0
 /**
  * Add element to form
  *
  * @param FElementInterface $element
  * @param string $position
  * @param bool $type If $type is TRUE, the element wile add before $position, else is after
  * @return \ZCMS\Core\Forms\ZForm
  */
 public function add(FElementInterface $element, $position = null, $type = null)
 {
     if ($this->bootstrap) {
         $class = $element->getAttribute("class");
         $classes = array_map("trim", explode(" ", $class));
         if (!in_array("form-control", $classes)) {
             $element->setAttribute("class", "form-control " . $class);
         }
     }
     if ($this->_autoGenerateTranslateLabel && $this->_formName != null) {
         $title = __($this->_formName . '_' . $element->getName());
         $attributes = $element->getAttributes();
         if (isset($attributes['required'])) {
             $title .= ' <span class="symbol required"></span>';
         }
         $element->setLabel($title);
     }
     return parent::add($element, $position, $type);
 }
Example #17
0
 public function testFormValidatorEntityBindSetters()
 {
     //Second element
     $address = new Text('address');
     $address->addValidator(new PresenceOf(array('message' => 'The address is required')));
     $telephone = new Text("telephone");
     $telephone->addValidator(new PresenceOf(array('message' => 'The telephone is required')));
     $entity = new ContactFormSettersGetters();
     $form = new Form();
     $form->add($address);
     $form->add($telephone);
     $form->bind(array('telephone' => '+44 123 45678', 'address' => 'hello'), $entity);
     $this->assertTrue($form->isValid());
     $this->assertEquals($entity->getTelephone(), '+44 123 45678');
     $this->assertEquals($entity->getAddress(), 'hello');
 }
Example #18
0
 public function testIssue706()
 {
     $form = new \Phalcon\Forms\Form();
     $form->add(new \Phalcon\Forms\Element\Text('name'));
     $form->add(new \Phalcon\Forms\Element\Text('before'), 'name', true);
     $form->add(new \Phalcon\Forms\Element\Text('after'), 'name');
     $data = array('before', 'name', 'after');
     $result = array();
     foreach ($form as $element) {
         $result[] = $element->getName();
     }
     $this->assertEquals($result, $data);
 }
Example #19
0
 public function testIssues1029()
 {
     $form = new Form();
     $form->add(new Text("name"));
     $telephone = new Text("telephone");
     $telephone->setLabel("The Telephone");
     $form->add($telephone);
     $this->assertEquals($form->label('name', array('class' => 'form-control')), '<label for="name" class="form-control">name</label>');
     $this->assertEquals($form->label('telephone', array('class' => 'form-control')), '<label for="telephone" class="form-control">The Telephone</label>');
 }
Example #20
0
 public function testIssue1992()
 {
     $form = new \Phalcon\Forms\Form();
     $name = new \Phalcon\Forms\Element\Text("name");
     $name->addValidator(new StringLength(array('min' => 10, 'messageMinimum' => 'The name is too short')));
     $form->add($name);
     $form->appendMessage("name", new \Phalcon\Validation\Message('Must be not empty '));
     $messages = $form->getMessages();
     $this->assertEquals(count($messages), 1);
     $this->assertFalse($form->isValid(array('name' => 'phalcon')));
     $this->assertEquals(count($messages), 1);
     $form->appendMessages("name", array(new \Phalcon\Validation\Message('Must be not empty '), new \Phalcon\Validation\Message('Must be an email address')));
     $messages = $form->getMessages();
     $this->assertEquals(count($messages), 3);
 }
Example #21
0
<?php

use Phalcon\Forms\Form, Phalcon\Forms\Element\Text, Phalcon\Forms\Element\Select;
$form = new Form();
$form->add(new Text("name"));
$form->add(new Text("telephone"));
$form->add(new Select("telephoneType", array('H' => 'Home', 'C' => 'Cell')));
 public function add($element, $postion = null, $type = null)
 {
     parent::add($element, $postion, $type);
 }
Example #23
0
    public function testVoltMacrosIssue11771()
    {
        $this->specify("Volt macros can't accept objects", function () {
            $this->removeFiles([PATH_DATA . 'views/macro/list.volt.php', PATH_DATA . 'views/macro/form_row.volt.php']);
            Di::reset();
            $view = new View();
            $di = new Di();
            $di->set('escaper', function () {
                return new Escaper();
            });
            $di->set('tag', function () {
                return new Tag();
            });
            $di->set('url', function () {
                return (new Url())->setBaseUri('/');
            });
            $view->setDI($di);
            $view->setViewsDir(PATH_DATA . 'views/');
            $view->registerEngines(array('.volt' => function ($view, $di) {
                return new Volt($view, $di);
            }));
            $object = new \stdClass();
            $object->foo = "bar";
            $object->baz = "buz";
            $object->pi = 3.14;
            $object->ary = ["some array"];
            $object->obj = clone $object;
            $view->setVar('object', $object);
            $view->start();
            $view->render('macro', 'list');
            $view->finish();
            ob_start();
            var_dump($object);
            $actual = ob_get_clean();
            // Trim xdebug first line (file path)
            $actual = substr($actual, strpos($actual, 'class'));
            $expected = substr($view->getContent(), strpos($view->getContent(), 'class'));
            expect($actual)->equals($expected);
            $form = new Form();
            $form->add(new Password('password'));
            $view->setVar('formLogin', $form);
            $view->start();
            $view->render('macro', 'form_row');
            $view->finish();
            $actual = <<<FORM
<div class="form-group">
    <label class="col-sm-2 control-label" for="password">password:</label>
    <div class="col-sm-6"><input type="password" id="password" name="password" class="form-control " /></div>
</div>
FORM;
            expect($actual)->equals($view->getContent());
            $this->removeFiles([PATH_DATA . 'views/macro/list.volt.php', PATH_DATA . 'views/macro/form_row.volt.php']);
        });
    }
 private static function setForm()
 {
     $form = new Form();
     //Numero do cartão
     foreach (self::rules() as $key => $value) {
         if ($value['type'] == 'text') {
             $chave = new Text("pagamento[{$key}]");
         } else {
             if ($value['type'] == 'hidden') {
                 $chave = new Hidden("pagamento[{$key}]");
             } else {
                 $arr = array();
                 if ($key == 'mes') {
                     $arr[''] = 'Mês de vencimento';
                     for ($i = 1; $i <= 12; $i++) {
                         $arr[$i] = $i;
                     }
                 } else {
                     if ($key == 'ano') {
                         $arr[''] = 'Ano de vencimento';
                         for ($i = date('Y'); $i <= date('Y', strtotime('+ 20 years')); $i++) {
                             $arr[$i] = $i;
                         }
                     } else {
                         $arr[''] = 'Numero de parcelas';
                     }
                 }
                 $chave = new Select("pagamento[{$key}]", $arr);
             }
         }
         foreach ($value['attributos'] as $k => $v) {
             $chave->setAttribute($k, $v);
         }
         $form->add($chave);
     }
     $html = '';
     foreach ($form as $key => $value) {
         $html .= "<div class='form-group'>" . $value . "</div>";
     }
     return $html;
 }
Example #25
0
 public function testIssue1190()
 {
     $object = new stdClass();
     $object->title = 'Hello "world!"';
     $form = new Phalcon\Forms\Form($object);
     $form->add(new Phalcon\Forms\Element\Text("title"));
     $actual = $form->render('title');
     $expected = '<input value="Hello &#x22;world!&#x22;" name="title" id="title" type="text" />';
     $this->assertEquals($actual, $expected);
 }