public function showModelErrors(Model $model, Form $form) { foreach ($model->getMessages() as $message) { $fieldName = $message->getField(); $form->addModelError($fieldName, $message->getMessage()); } }
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); } } }
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; }
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; }
public function isValid($data = null, $entity = null) { if (!$this->security->checkToken()) { return false; } return parent::isValid($data, $entity); }
public function getMessages($byItemName = false) { $messages = array(); foreach (parent::getMessages(true) as $key => $message) { $messages[$key] = $message[0]->getMessage(); } return $messages; }
public function getMessagesFor($name) { $messages = parent::getMessagesFor($name); if (!isset($this->_messages[$name])) { $this->_messages[$name] = $messages; } return $messages; }
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("telephone", array("size" => 10, "maxlength" => 50))); $form->add(new Text("city", array("size" => 14, "maxlength" => 250))); $form->add(new Textarea("address", array("cols" => 14, "rows" => 5, "maxlength" => 50))); $form->add(new Text("contacts", array("size" => 14, "maxlength" => 50))); return $form; }
/** * 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]; } }
/** * Check if form is valid. If so set the values to the config array. * * @param array $data The form data posted. * @return bool Whether or not form is valid. */ public function IsValid($data = null, $entity = null) { $valid = parent::IsValid($data, $entity); if ($valid) { $this->_config->application->title = $data['title']; $this->_config->application->phalconCryptKey = $data['cryptkey']; $this->_config->application->background = $data['bgcolor']; $this->_config->application->debug = $data['debug'] ? '1' : '0'; } return $valid; }
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; }
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; }
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'); }
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; }
/** * Returns the element's value * * @return mixed */ public function getValue() { $value = null; //Get the related form if (is_object($this->_form) === true) { $hasDefaultValue = Tag::hasValue($this->_name); if ($hasDefaultValue === false) { //Get the possible value for the widget $value = $this->_form->getValue($this->_name); } } //Assign the default value if there is no form available if (is_null($value) === true) { $value = $this->_value; } return $value; }
/** * 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); }
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; }
public function getAction() { $requri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; return parent::getAction() ?: $requri; }
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'); }
/** * Rewrite validation class to handle afterValidateEvent * @param null $data * @param null $entity * @return bool */ public function isValid($data = null, $entity = null) { return parent::isValid($data, $entity) && $this->afterValidation($data); }
private function getArrayValue(array $matches) { $baseName = $matches[0]; $value = parent::getValue($baseName); foreach ($matches as $key => $match) { if ($key) { if (isset($value[$match])) { $value = $value[$match]; } else { return null; } } } return $value; }
public function add($element, $postion = null, $type = null) { parent::add($element, $postion, $type); }
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); }
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; }
/** * @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); }); }
/** * @param Form $form * @param string $messageType * @return \Phalcon\Http\ResponseInterface */ public function showInvalidMessagesAsJson(Form $form, $messageType = 'warning') { $messages = $form->getMessages(); $content = array(); foreach ($messages as $message) { $content[] = array('code' => 10001, 'message' => $message->getMessage(), 'message_human' => $this->getDI()->getTranslate()->query($message->getMessage())); } $this->response->setStatusCode(400, $this->recommendedReasonPhrases[400]); return $this->response->setJsonContent(array('errors' => $content)); }
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); }
/** * Check if form is valid. If so set the values to the config array. * * @param array $data The form data posted. * @return bool Whether or not form is valid. */ public function IsValid($data = null, $entity = null) { $valid = parent::IsValid($data, $entity); if ($valid) { $this->_config->dashboard->checkDeviceStatesInterval = $data['check-devicestate-interval']; $this->_config->dashboard->alertTimeout = $data['alert-timeout']; $this->_config->dashboard->phpSysInfoURL = $data['phpsysinfo-url']; $this->_config->dashboard->phpSysInfoVCore = $data['phpsysinfo-vcore']; $this->_config->dashboard->transmissionURL = $data['transmission-url']; $this->_config->dashboard->transmissionUsername = $data['transmission-username']; $this->_config->dashboard->transmissionPassword = $data['transmission-password']; $this->_config->dashboard->transmissionUpdateInterval = $data['transmission-update-interval']; $this->_config->dashboard->rotateMoviesInterval = $data['rotate-movies-interval']; $this->_config->dashboard->rotateEpisodesInterval = $data['rotate-episodes-interval']; $this->_config->dashboard->rotateAlbumsInterval = $data['rotate-albums-interval']; } return $valid; }
public function render($name, $attributes = null) { if (!$this->prefix) { return parent::render($name, $attributes); } $attributes = array_merge(array('name' => $this->prefix . '[' . $this->get($name)->getName() . ']'), (array) $attributes); return parent::render($name, $attributes); }
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>'); }