public function index() { $user = System::getUser(); $form = new Form('form-profile'); $form->setAttribute('data-noajax', 'true'); $form->binding = $user; $fieldset = new Fieldset(System::getLanguage()->_('General')); $firstname = new Text('firstname', System::getLanguage()->_('Firstname')); $firstname->binding = new Databinding('firstname'); $lastname = new Text('lastname', System::getLanguage()->_('Lastname')); $lastname->binding = new Databinding('lastname'); $email = new Text('email', System::getLanguage()->_('EMail'), true); $email->binding = new Databinding('email'); $email->blacklist = $this->getListOfMailAdresses($user); $email->error_msg[4] = System::getLanguage()->_('ErrorMailAdressAlreadyExists'); $language = new Radiobox('lang', System::getLanguage()->_('Language'), L10N::getLanguages()); $language->binding = new Databinding('lang'); $fieldset->addElements($firstname, $lastname, $email, $language); $form->addElements($fieldset); $fieldset = new Fieldset(System::getLanguage()->_('Password')); $password = new Password('password', System::getLanguage()->_('Password')); $password->minlength = PASSWORD_MIN_LENGTH; $password->binding = new Databinding('password'); $password2 = new Password('password2', System::getLanguage()->_('ReenterPassword')); $fieldset->addElements($password, $password2); $form->addElements($fieldset); $fieldset = new Fieldset(System::getLanguage()->_('Settings')); $quota = new Text('quota', System::getLanguage()->_('Quota')); if ($user->quota > 0) { $quota->value = System::getLanguage()->_('QuotaAvailabe', Utils::formatBytes($user->getFreeSpace()), Utils::formatBytes($user->quota)); } else { $quota->value = System::getLanguage()->_('Unlimited'); } $quota->readonly = true; $fieldset->addElements($quota); $form->addElements($fieldset); if (Utils::getPOST('submit', false) !== false) { if (!empty($password->value) && $password->value != $password2->value) { $password2->error = System::getLanguage()->_('ErrorInvalidPasswords'); } else { if ($form->validate()) { $form->save(); System::getUser()->save(); System::getSession()->setData('successMsg', System::getLanguage()->_('ProfileUpdated')); System::forwardToRoute(Router::getInstance()->build('ProfileController', 'index')); exit; } } } else { $form->fill(); } $form->setSubmit(new Button(System::getLanguage()->_('Save'), 'floppy-disk')); $smarty = new Template(); $smarty->assign('title', System::getLanguage()->_('MyProfile')); $smarty->assign('heading', System::getLanguage()->_('MyProfile')); $smarty->assign('form', $form->__toString()); $smarty->display('form.tpl'); }
function add_elements($elements) { $args['class'] = 'well'; for ($i = 0; $i < $this->group_count; $i++) { $fieldset = new Fieldset($this, $i, $args); $fieldset->add_elements($elements); $this->elements[$i] = $fieldset; } }
/** * Set a Model's properties as fields on a Fieldset, which will be created with the Model's * classname if none is provided. * * @param string * @param Fieldset|null * @return Fieldset */ public static function set_fields($class, $fieldset = null) { $properties = $class::properties(); if (is_null($fieldset)) { $fieldset = \Fieldset::instance($class); if (!$fieldset) { $fieldset = \Fieldset::factory($class); } } foreach ($properties as $p => $settings) { $field = $fieldset->add($p, !empty($settings['label']) ? $settings['label'] : $p); if (empty($settings['validation'])) { continue; } else { foreach ($settings['validation'] as $rule => $args) { if (is_int($rule) and is_string($args)) { $args = array($args); } else { array_unshift($args, $rule); } call_user_func_array(array($field, 'add_rule'), $args); } } } return $fieldset; }
/** * ユーザ登録 * * @access public * @return View */ public function action_regist() { $view = View::forge('admin/regist'); $form = Fieldset::forge(); $form->form()->set_attribute('class', 'form form-horizontal'); $form->add('username', 'ログインID', array('class' => 'form-control'))->add_rule('required')->add_rule('min_length', 3)->add_rule('max_length', 50); $form->add('password', 'パスワード', array('class' => 'form-control'))->add_rule('required')->add_rule('min_length', 3)->add_rule('max_length', 20); $form->add('email', 'Eメール', array('class' => 'form-control'))->add_rule('required')->add_rule('valid_email'); $form->add('submit', '', array('type' => 'submit', 'value' => '登録', 'class' => 'btn btn-primary')); if (\Input::post()) { $val = $form->validation(); if ($val->run()) { $result = \Auth::create_user(\Input::post('username'), \Input::post('password'), \Input::post('email'), 1, array()); if ($result) { $view->set_global('massage', array('css' => 'success', 'content' => '登録に成功しました。')); } else { $form->repopulate(); $view->set_global('massage', array('css' => 'danger', 'content' => '既に登録済みの情報が使用されています。')); } } else { $form->repopulate(); $view->set_global('errors', $val->error()); } } $form->build('/form/confirm'); $view->set_safe('form', $form); return $view; }
/** * Set a Model's properties as fields on a Fieldset, which will be created with the Model's * classname if none is provided. * * @param string * @param Fieldset|null * @return Fieldset */ public static function set_fields($obj, $fieldset = null) { static $_generated = array(); $class = is_object($obj) ? get_class($obj) : $obj; if (is_null($fieldset)) { $fieldset = \Fieldset::instance($class); if (!$fieldset) { $fieldset = \Fieldset::factory($class); } } !array_key_exists($class, $_generated) and $_generated[$class] = array(); if (in_array($fieldset, $_generated[$class], true)) { return $fieldset; } $_generated[$class][] = $fieldset; $fieldset->validation()->add_callable($obj); $properties = is_object($obj) ? $obj->properties() : $class::properties(); foreach ($properties as $p => $settings) { $field = $fieldset->add($p, !empty($settings['label']) ? $settings['label'] : $p); if (empty($settings['validation'])) { continue; } else { foreach ($settings['validation'] as $rule => $args) { if (is_int($rule) and is_string($args)) { $args = array($args); } else { array_unshift($args, $rule); } call_user_func_array(array($field, 'add_rule'), $args); } } } return $fieldset; }
/** * 2015-11-19 * @override * @see \Df\Framework\Form\Element\Fieldset::onFormInitialized() * @used-by \Df\Framework\Plugin\Data\Form\Element\AbstractElement::afterSetForm() * @return void */ public function onFormInitialized() { parent::onFormInitialized(); $this->addClass('df-array'); // 2015-12-29 // Невидимая строка-шаблон. df_hide($this->field('template', $this->itemFormElement())); /** @var int $itemId */ $itemId = 0; foreach ($this->v() as $key => $data) { /** @var string|int $key */ /** @var string|array(string => mixed) $data */ /** * 2016-07-30 * Раньше тут стоял код: // 2015-12-30 // https://github.com/mage2pro/core/tree/b1f6809b7723d8426636bb892b852f408bdc5650/Framework/view/adminhtml/web/formElement/array/main.js#L131 if (\Df\Config\A::FAKE !== $key) { $this->field($itemId++, $this->itemType(), null, $data); } * Теперь у нас ключ @see \Df\Config\A::FAKE удаляется в методе * @see \Df\Config\Backend\ArrayT::processA() * поэтому здесь его уже быть не должно. */ df_assert_ne(\Df\Config\A::FAKE, $key); $this->field($itemId++, $this->itemFormElement(), null, $data); } df_fe_init($this, __CLASS__, df_fa(), [], 'array'); }
public function action_create() { $fieldset = Fieldset::forge()->add_model('Model_Post'); $form = $fieldset->form(); $form->add('submit', '', array('type' => 'submit', 'value' => 'Add New Post', 'class' => 'btn btn-large')); if (Input::method() == 'POST') { if ($fieldset->validation()->run() == true) { $fields = $fieldset->validated(); $post = Model_Post::forge(); foreach ($fields as $key => $value) { $post->{$key} = $value; } $post->dive_time = Model_Post::calc_diff_of_time($post->exit, $post->entry); $post->creatures = Model_Creature::parseCreatures(Input::post('report')); if ($post->save()) { Session::set_flash('success', e('Added post #' . $post->id . '.')); Response::redirect('admin/posts'); } else { Session::set_flash('error', e('Could not save post.')); } } else { Session::set_flash('error', $val->error()); } } $this->template->set_global('form', $form->build(), false); $this->template->title = "Posts"; $this->template->content = View::forge('admin/posts/create'); }
private function get_form($type = 0) { $form = Fieldset::instance(); if (count($form->field()) > 0) { return $form; } switch ($type) { case SettingType::PASSWORD: $form->add("mail_address_new", "新しいメールアドレス"); $form->add("mail_address_new_confirm", "新しいメールアドレス(確認)"); $form->add("password", "現在のパスワード")->add_rule("required"); $form->add("password_new", "新しいパスワード")->add_rule("required")->add_rule("min_length", 4)->add_rule("max_length", 30)->add_rule("valid_string", array("alpha", "numeric")); $form->add("password_new_confirm", "新しいパスワード(確認)")->add_rule("required")->add_rule("match_field", "password_new"); break; case SettingType::MAILADDRESS: $form->add("mail_address_new", "新しいメールアドレス")->add_rule("required")->add_rule("valid_email"); $form->add("mail_address_new_confirm", "新しいメールアドレス(確認)"); $form->add("password", "現在のパスワード"); $form->add("password_new", "新しいパスワード"); $form->add("password_new_confirm", "新しいパスワード(確認)"); break; default: break; } return $form; }
public function getRadioCheckbox($renderApi, $unit, $fieldId, $postRequestValue = null, $required = false) { $formField = new \Fieldset(); $listOptions = $this->listOptions->getListOptions($renderApi, $unit); $inputName = strlen($renderApi->getFormValue($unit, 'inputName')) > 0 ? $renderApi->getFormValue($unit, 'inputName') . "[]" : $fieldId . "[]"; if ($listOptions->hasOptions()) { $optionCount = 0; $options = $listOptions->getOptions(); $optionsLength = count($options); foreach ($options as $option) { /* @var $option \Option */ $properties = $unit->getFormValues(); if ($properties["listType"] === \ListType::RADIO) { $choiceField = new \RadioButtonField(); } elseif ($properties["listType"] === \ListType::CHECKBOX) { $choiceField = new \CheckboxField(); } $optionId = $fieldId . '_' . $optionCount; $elementProperties = $choiceField->getElementProperties(); $elementProperties->addAttribute("value", $option->getValue()); $elementProperties->addAttribute("name", $inputName); $elementProperties->addAttribute("id", $optionId); // set required attribute for radio options or when there is only one checkbox // don't set for multiple checkboxes to match server-side validation logic if ($required && ($properties["listType"] === \ListType::RADIO || $optionsLength === 1)) { $elementProperties->addAttribute("required", null); } $request = new Request(); $request->isPostRequest(); if (!$request->isPostRequest() && $option->isChecked() || !is_null($postRequestValue) && in_array($option->getValue(), $postRequestValue)) { $elementProperties->addAttribute("checked", null); } $label = new \Label(); $label->add($choiceField); $label->add(new \Span($option->getName())); $labelProperties = $label->getElementProperties(); $labelProperties->addAttribute("for", $optionId); $formField->add($label); $optionCount++; } } if ($this->formSubmit->isValid($renderApi, $unit) && !$this->isValidValue($unit, $postRequestValue)) { $formField->add($this->getErrorMessage($unit, $postRequestValue)); $formField->getElementProperties()->addClass('vf__error'); } return $formField; }
public static function createFieldset() { $contact = self::forge(); $fieldset = Fieldset::forge(); $fieldset->add_model($contact); $fieldset->add('email2', 'メールアドレス確認用')->add_rule('required')->add_rule('match_field', 'email'); return $fieldset; }
/** * Set options for a fieldset. Accepted options are: * - input_filter_spec: specification to be returned by getInputFilterSpecification * * @param array|Traversable $options * @return Element|ElementInterface|FieldsetInterface * @throws Exception\InvalidArgumentException */ public function setOptions($options) { parent::setOptions($options); if (isset($options['input_filter_spec'])) { $this->setInputFilterSpecification($options['input_filter_spec']); } return $this; }
public static function validate_registration(Fieldset $form, $auth) { $form->field('password')->add_rule('match_value', $form->field('password2')->get_attribute('value')); $val = $form->validation(); $val->set_message('required', 'The field :field is required'); $val->set_message('valid_email', 'The field :field must be an email address'); $val->set_message('match_value', 'The passwords must match'); if ($val->run()) { $username = $form->field('username')->get_attribute('value'); $password = $form->field('password')->get_attribute('value'); $email = $form->field('email')->get_attribute('value'); try { $user = $auth->create_user($username, $password, $email); } catch (Exception $e) { $error = $e->getMessage(); } if (isset($user)) { $auth->login($username, $password); } else { if (isset($error)) { $li = $error; } else { $li = 'Something went wrong with creating the user!'; } $errors = Html::ul(array($li)); return array('e_found' => true, 'errors' => $errors); } } else { $errors = $val->show_errors(); return array('e_found' => true, 'errors' => $errors); } }
public function forge_form() { $form = Fieldset::forge(); $form->add('name', '名前')->add_rule('trim')->add_rule('required')->add_rule('no_tab_and_newline')->add_rule('max_length', 50); $form->add('email', 'メールアドレス')->add_rule('trim')->add_rule('required')->add_rule('no_tab_and_newline')->add_rule('max_length', 100)->add_rule('valid_email'); $form->add('comment', 'コメント', array('type' => 'textarea', 'cols' => 70, 'rows' => 6))->add_rule('required')->add_rule('max_length', 400); $form->add('submit', '', array('type' => 'submit', 'value' => '確認')); return $form; }
/** * ログイン用のFieldsetをレスポンスします * * @access public * @return Fieldset fieldset * @author shimma */ public function createFieldset() { $fieldset = Session::get_flash('login.fieldset'); if (!$fieldset) { $fieldset = \Fieldset::forge('login'); $fieldset->add('email', 'Email')->add_rule('required')->add_rule('valid_email'); $fieldset->add('password', 'Password')->add_rule('required'); } return $fieldset; }
protected function renderContent() { $this->initializeRendering(); $content = ''; $content .= $this->openTag('div', array('class' => 'ObjectPicker ' . implode(' ', $this->metadata['listenToEvents']))); // render the an hidden input, as fallback empty post value: foreach ($this->getChildren() as $child) { $content .= $this->selfClosingTag('input', array('type' => 'hidden', 'value' => '', 'name' => $this->getControlName($child->getAttribute('name')))); } $content .= $this->renderMeta(); $content .= $this->renderObjects(); $content .= $this->closeTag('div'); if ($this->hasAttribute('template')) { $fieldsetWidget = new Fieldset($this->view); $fieldsetWidget->setAttribute('template', $this->getAttribute('template'))->setAttribute('icon-before', $this->getAttribute('icon-before'))->insert($this->view->literal($content)); return $fieldsetWidget; } return $content; }
/** * Test of "for" attribute in label tag */ public function test_for_in_label() { $form = Fieldset::forge(__METHOD__); $ops = array('male', 'female'); $form->add('gender', '', array('options' => $ops, 'type' => 'radio', 'value' => 1)); $output = $form->build(); $output = str_replace(array("\n", "\t"), "", $output); $expected = '<form action="welcome/index" accept-charset="utf-8" method="post"><table><tr><td class=""></td><td class=""><input type="radio" value="0" id="form_gender_0" name="gender" /> <label for="form_gender_0">male</label><br /><input type="radio" value="1" id="form_gender_1" name="gender" checked="checked" /> <label for="form_gender_1">female</label><br /><span></span></td></tr></table></form>'; $this->assertEquals($expected, $output); }
protected function set_login_validation() { Fieldset::reset(); $this->login_val = Validation::forge('site_login'); $options = array('1' => '次回から自動的にログイン'); $this->login_val->add('rememberme', '', array('type' => 'checkbox', 'options' => $options))->add_rule('checkbox_val', $options); $this->login_val->add_model(Model_MemberAuth::forge()); $this->login_val->fieldset()->field('email')->delete_rule('unique'); View::set_global('login_val', $this->login_val); }
/** * Test of "for" attribute in label tag */ public function test_for_in_label() { $form = Fieldset::forge(__METHOD__)->set_config(array('prep_value' => true, 'auto_id' => true, 'auto_id_prefix' => 'form_', 'form_method' => 'post', 'form_template' => "\n\t\t{open}\n\t\t<table>\n{fields}\n\t\t</table>\n\t\t{close}\n", 'fieldset_template' => "\n\t\t<tr><td colspan=\"2\">{open}<table>\n{fields}</table></td></tr>\n\t\t{close}\n", 'field_template' => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{field} <span>{description}</span> {error_msg}</td>\n\t\t</tr>\n", 'multi_field_template' => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{group_label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{fields}\n\t\t\t\t{field} {label}<br />\n{fields}<span>{description}</span>\t\t\t{error_msg}\n\t\t\t</td>\n\t\t</tr>\n", 'error_template' => '<span>{error_msg}</span>', 'group_label' => '<span>{label}</span>', 'required_mark' => '*', 'inline_errors' => false, 'error_class' => 'validation_error', 'tabular_form_template' => "<table>{fields}</table>\n", 'tabular_field_template' => "{field}", 'tabular_row_template' => "<tr>{fields}</tr>\n", 'tabular_row_field_template' => "\t\t\t<td>{label}{required} {field} {icon} {error_msg}</td>\n", 'tabular_delete_label' => "Delete?")); $ops = array('male', 'female'); $form->add('gender', '', array('options' => $ops, 'type' => 'radio', 'value' => 1)); $output = $form->build(); $output = str_replace(array("\n", "\t"), "", $output); $expected = '<form action="welcome/index" accept-charset="utf-8" method="post"><table><tr><td class=""></td><td class=""><input type="radio" value="0" id="form_gender_0" name="gender" /> <label for="form_gender_0">male</label><br /><input type="radio" value="1" id="form_gender_1" name="gender" checked="checked" /> <label for="form_gender_1">female</label><br /><span></span></td></tr></table></form>'; $this->assertEquals($expected, $output); }
public function action_add($id = null) { $this->data['isUpdate'] = $isUpdate = $id !== null ? true : false; // Prepare form fieldset $form = \Fieldset::forge('category_form', array('form_attributes' => array('class' => 'form-horizontal special'))); $form->add_model('Blog\\Model_Category'); $form->add('add', '', array('type' => 'submit', 'value' => $isUpdate ? __('backend.edit') : __('backend.add'), 'class' => 'btn btn-primary')); // Get or create the post if ($isUpdate) { $this->data['category'] = $category = Model_Category::find($id); $this->dataGlobal['pageTitle'] = __('backend.category.edit'); } else { $this->data['category'] = $category = Model_Category::forge(); $this->dataGlobal['pageTitle'] = __('backend.category.add'); } $form->populate($category); // If POST submit if (\Input::post('add')) { $form->validation()->run(); if (!$form->validation()->error()) { // Populate the category $category->from_array(array('name' => $form->validated('name'), 'slug' => $form->validated('slug') != '' ? \Inflector::friendly_title($form->validated('slug'), '-', true) : \Inflector::friendly_title($form->validated('name'), '-', true), 'parent_id' => $form->validated('parent_id'))); if ($category->save()) { // Delete cache \Cache::delete('sidebar'); // Category Post count update foreach (Model_Category::find('all') as $category) { $category->post_count = count($category->posts); $category->save(); } if ($isUpdate) { // \Messages::success(__('backend.category.edited')); \Session::set_flash('success', __('backend.category.edited')); } else { // \Messages::success(__('backend.category.added')); \Session::set_flash('success', __('backend.category.added')); } \Response::redirect_back(\Router::get('admin_category')); } else { // \Messages::error(__('error')); \Session::set_flash('error', __('error')); } } else { // Output validation errors foreach ($form->validation()->error() as $error) { echo $error; // \Messages::error($error); \Session::set_flash('error', $error); } } } $form->repopulate(); $this->data['form'] = $form; return \Response::forge(\View::forge('backend/category/add')->set($this->data, null, false)); }
public static function populate_register_fieldset(Fieldset $form) { $form->add('username', 'Username:'******'required'); $form->add('password', 'Choose Password:'******'type' => 'password'))->add_rule('required'); $form->add('password2', 'Re-type Password:'******'type' => 'password'))->add_rule('required'); $form->add('email', 'E-mail:')->add_rule('required')->add_rule('valid_email'); $form->add('submit', ' ', array('type' => 'submit', 'value' => 'Register')); return $form; }
public function post_register() { $fieldset = Model_User::populate_register_fieldset(Fieldset::forge('register')); $fieldset->repopulate(); $result = Model_User::validate_registration($fieldset, Auth::instance()); if ($result['e_found']) { return $this->get_register($fieldset, $result['errors']); } Session::set_flash('success', 'User created.'); Response::redirect('./'); }
private function get_form() { $form = Fieldset::instance(); if (count($form->field()) > 0) { return $form; } $form->add('email', 'メールアドレス')->add_rule('required')->add_rule('max_length', 30)->add_rule('valid_email'); $form->add('password', 'パスワード')->add_rule('required')->add_rule('max_length', 30); $form->add('remember', 'パスワードを保存する')->add_rule('match_value', '1'); return $form; }
private function renderWidgetList($value, $choices, $attributes) { $name = $this->getAttribute('name'); $flags = $this->getAttribute('flags'); $hiddenWidget = new Hidden($this->view); $hiddenWidget->setAttribute('flags', $flags)->setAttribute('value', '')->setAttribute('class', 'Hidden')->setAttribute('name', $name); $contentWidget = new Literal($this->view); $contentWidget->setAttribute('data', $this->generateSelectorContentWidgetList($name, $value, $choices, $flags)); $panelWidget = new Panel($this->view); $panelWidget->setAttribute('class', $attributes['class'])->setAttribute('name', $name)->insert($hiddenWidget)->insert($contentWidget); if ($this->getAttribute('flags') & \Nethgui\Renderer\WidgetFactoryInterface::LABEL_NONE) { return $panelWidget->renderContent(); } $fieldsetWidget = new Fieldset($this->view); $fieldsetWidget->setAttribute('template', $this->getAttribute('label', $this->getTranslateClosure($name . '_label')))->setAttribute('flags', $this->getAttribute('flags')); if ($this->hasAttribute('icon-before')) { $fieldsetWidget->setAttribute('icon-before', $this->getAttribute('icon-before')); } $fieldsetWidget->insert($panelWidget); return $fieldsetWidget->renderContent(); }
/** * Mmeber setting password * * @access public * @return Response */ public function action_password() { if (!($form = Fieldset::instance('setting_password'))) { $form = $this->form_setting_password(); } if (Input::method() === 'POST') { $form->repopulate(); } $this->set_title_and_breadcrumbs(term('site.password', 'form.update'), array('member/setting/' => term('site.setting', 'form.update')), $this->u); $this->template->content = View::forge('_parts/setting/password'); $this->template->content->set_safe('html_form', $form->build('member/setting/change_password')); }
private function get_form() { $form = Fieldset::instance(); if (count($form->field()) > 0) { return $form; } $form->add('ope'); $form->add('id'); $form->add('name', 'お名前')->add_rule('required')->add_rule('max_length', 50); $form->add('email', 'メールアドレス')->add_rule('required'); $form->add('status', 'ステータス')->add_rule('required'); return $form; }
/** * Resend password * * @access public * @return Response */ public function action_resend_password() { if (!($form = Fieldset::instance('resend_password'))) { $form = $this->form_resend_password(); } if (Input::method() === 'POST') { $form->repopulate(); } $this->set_title_and_breadcrumbs(term('site.password') . 'の再設定'); $this->template->content = View::forge('member/recover/resend_password'); $this->template->content->set_safe('html_form', $form->build('member/recover/send_reset_password_mail')); // form の action に入る }
/** * Mmeber leave * * @access public * @return Response */ public function action_index() { if (!($form = Fieldset::instance('leave'))) { $form = $this->form_leave(); } if (Input::method() === 'POST') { $form->repopulate(); } $this->set_title_and_breadcrumbs(term('site.left'), array('member/setting' => term('site.setting', 'form.update')), $this->u); $this->template->content = View::forge('member/leave/index'); $this->template->content->set_safe('html_form', $form->build('member/leave/confirm')); // form の action に入る }
public function action_add($id = null) { $this->data['isUpdate'] = $isUpdate = $id !== null ? true : false; // Prepare form fieldset $form = \Fieldset::forge('post_form', array('form_attributes' => array('class' => 'form-horizontal'))); $form->add_model('Model_Post'); $form->add('add', '', array('type' => 'submit', 'value' => $isUpdate ? __('backend.edit') : __('backend.add'), 'class' => 'btn btn-primary')); // Get or create the post if ($isUpdate) { $this->data['post'] = $post = \Model_Post::find($id); $this->dataGlobal['pageTitle'] = __('backend.post.edit'); } else { $this->data['post'] = $post = \Model_Post::forge(); $this->dataGlobal['pageTitle'] = __('backend.post.add'); } $form->populate($post); // If POST submit if (\Input::post('add')) { $form->validation()->run(); if (!$form->validation()->error()) { // Populate the post $post->from_array(array('name' => $form->validated('name'), 'slug' => $form->validated('slug') != '' ? \Inflector::friendly_title($form->validated('slug')) : \Inflector::friendly_title($form->validated('name')), 'category_id' => $form->validated('category_id'), 'user_id' => $form->validated('user_id'), 'content' => $form->validated('content'))); if ($post->save()) { // Delete cache \Cache::delete('sidebar'); // Category Post count update foreach (\Model_Category::find('all') as $category) { $category->post_count = count($category->posts); $category->save(); } if ($isUpdate) { \Messages::success(__('backend.post.edited')); } else { \Messages::success(__('backend.post.added')); } \Response::redirect_back(\Router::get('admin_post')); } else { \Messages::error(__('error')); } } else { // Output validation errors foreach ($form->validation()->error() as $error) { \Messages::error($error); } } } $form->repopulate(); $this->data['form'] = $form; $this->theme->set_partial('content', 'backend/post/add')->set($this->data, null, false); }
public function form() { $form = Fieldset::forge(); $form->add('name', '名前')->add_rule('trim')->add_rule('required')->add_rule('no_controll')->add_rule('max_length', 20); $form->add('email', 'メールアドレス')->add_rule('trim')->add_rule('required')->add_rule('no_controll')->add_rule('valid_email'); $form->add('comment', 'コメント', array('type' => 'textarea', 'cols' => 70, 'rows' => 6))->add_rule('required')->add_rule('max_length', 400); $ops = array('男性' => '男性', '女性' => '女性'); $form->add('gender', '性別', array('options' => $ops, 'type' => 'radio'))->add_rule('in_array', $ops); $ops = array('' => '選択してください', '使い方について' => '使い方について', 'その他' => 'その他'); $form->add('kind', '問い合わせの種類', array('options' => $ops, 'type' => 'select'))->add_rule('in_array', $ops); $ops = array('カワセミ' => 'カワセミ', 'ヒヨドリ' => 'ヒヨドリ', 'オオルリ' => 'オオルリ'); $form->add('lang', '好きな鳥は?', array('options' => $ops, 'type' => 'checkbox'))->add_rule('in_array', $ops)->add_rule('not_required_array'); $form->add('submit', '', array('type' => 'submit', 'value' => '確認')); return $form; }
private function get_form() { $form = Fieldset::instance(); if (count($form->field()) > 0) { return $form; } $form->add("contact_type", "お問い合わせ項目")->add_rule("required")->add_rule("match_pattern", "/" . implode("|", array_keys($this->contactType)) . "/"); $form->add("name", "お名前")->add_rule("required")->add_rule("max_length", 50); $form->add("name_kana", "お名前(フリガナ)")->add_rule("required")->add_rule("max_length", 50)->add_rule("valid_katakana"); $form->add("tel", "電話番号")->add_rule("required")->add_rule("valid_tel"); $form->add("mail_address", "メールアドレス")->add_rule("required")->add_rule("valid_email"); $form->add("mail_address_confirm", "メールアドレス(確認)")->add_rule("required")->add_rule("match_field", "mail_address"); $form->add("contact_detail", "お問い合わせ内容")->add_rule("required")->add_rule("max_length", 1000); $form->add("agree", "同意")->add_rule("match_value", 1); return $form; }