/** * ユーザ登録 * * @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; }
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'); }
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; }
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; }
/** * 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); }
/** * ログイン用の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; }
/** * 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); }
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 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('./'); }
public function __construct($fieldset, array $config = array()) { if ($fieldset instanceof Fieldset) { $fieldset->form($this); $this->fieldset = $fieldset; } else { $this->fieldset = \Fieldset::forge($fieldset, array('form_instance' => $this)); } foreach ($config as $key => $val) { $this->set_config($key, $val); } }
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; }
public function before() { //Fieldsetオブジェクトを生成 $config = array('form_attributes' => array('action' => 'http://localhost/~marikonakagawa/courseMngr/public/index.php/form/confirm')); $user_form = Fieldset::forge('user_form', $config); $user_form->add('name', 'ユーザ名', array('type' => 'text', 'size' => 40, 'placeholder' => 'ユーザ名を入力してください')); $user_form->add('email', 'メールアドレス', array('type' => 'email', 'size' => 40)); $user_form->add('password1', 'パスワード', array('type' => 'password', 'size' => 40)); $user_form->add('password2', '確認用', array('type' => 'password', 'size' => 40)); $user_form->add('submit', '', array('type' => 'submit', 'value' => '登録')); $user_form->field('name')->add_rule('required'); $user_form->field('email')->add_rule('required')->add_rule('valid_email'); $user_form->field('password1')->add_rule('required')->add_rule('min_length', 8)->add_rule('max_length', 12)->add_rule('valid_string', array('alpha', 'numeric', 'dashes', 'utf8')); $user_form->field('password2')->add_rule('required')->add_rule('match_field', 'password1'); $this->user_form = $user_form; }
/** * 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::forge($class); } } !array_key_exists($class, $_generated) and $_generated[$class] = array(); if (in_array($fieldset, $_generated[$class], true)) { return $fieldset; } $_generated[$class][] = $fieldset; $primary_keys = is_object($obj) ? $obj->primary_key() : $class::primary_key(); $properties = is_object($obj) ? $obj->properties() : $class::properties(); foreach ($properties as $p => $settings) { if (\Arr::get($settings, 'skip', in_array($p, $primary_keys))) { continue; } if (isset($settings['form']['options'])) { foreach ($settings['form']['options'] as $key => $value) { is_array($value) or $settings['form']['options'][$key] = \Lang::get($value, array(), false) ?: $value; } } // field attributes can be passed in form key $attributes = isset($settings['form']) ? $settings['form'] : array(); // label is either set in property setting, as part of form attributes or defaults to fieldname $label = isset($settings['label']) ? $settings['label'] : (isset($attributes['label']) ? $attributes['label'] : $p); $label = \Lang::get($label, array(), false) ?: $label; // create the field and add validation rules $field = $fieldset->add($p, $label, $attributes); if (!empty($settings['validation'])) { 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; }
/** * 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::forge($class); } } !array_key_exists($class, $_generated) and $_generated[$class] = array(); if (in_array($fieldset, $_generated[$class], true)) { return $fieldset; } $_generated[$class][] = $fieldset; $primary_keys = is_object($obj) ? $obj->primary_key() : $class::primary_key(); $properties = is_object($obj) ? $obj->properties() : $class::properties(); foreach ($properties as $p => $settings) { if (in_array($p, $primary_keys)) { continue; } if (isset($settings['form']['options'])) { foreach ($settings['form']['options'] as $key => $value) { $settings['form']['options'][$key] = \Lang::line($value) ?: $value; } } $label = isset($settings['label']) ? $settings['label'] : $p; $attributes = isset($settings['form']) ? $settings['form'] : array(); $field = $fieldset->add($p, $label, $attributes); if (!empty($settings['validation'])) { 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; }
/** * The module index * * @return Response */ public function action_index() { \View::set_global('full_page', true); $this->data['title'] = 'Login'; // create the form fieldset, do not add an {open}, a closing ul and a {close}, we have a custom form layout! $fieldset = \Fieldset::forge('login'); $fieldset->add('username', 'Username', array('maxlength' => 50), array(array('required')))->add('password', 'Password', array('type' => 'password', 'maxlength' => 255), array(array('required'), array('min_length', 8))); // was the login form posted? if (\Input::post()) { // run the form validation if (!$fieldset->validation()->run()) { // set any error messages we need to display foreach ($fieldset->validation()->error() as $error) { \Messages::error($error); } } else { try { if (\Sentry::user(\Input::param('username'))->is_admin()) { // check the credentials. $valid_login = \Sentry::login(\Input::param('username'), \Input::param('password'), true); if ($valid_login) { \Messages::success('You have logged in successfully'); if (\Session::get('redirect_to')) { $redirect = \Session::get('redirect_to'); \Session::delete('redirect_to'); } \Response::redirect(isset($redirect) ? $redirect : 'admin'); } else { \Messages::error('Username and/or password is incorrect'); } } else { \Messages::error('Username and/or password is incorrect'); } } catch (\SentryAuthException $e) { $errors = $e->getMessage(); \Messages::error($errors); } } } \Theme::instance()->set_partial('content', 'views/login')->set('fieldset', $fieldset, false); }
public function action_register() { $auth = Auth::instance(); $form = Fieldset::forge('register'); $view = View::forge('users/register'); Model_User::register($form); if (Input::post()) { $form->repopulate(); $result = Model_User::validate_registration($form, $auth); if ($result['e_found']) { $view->set('errors', $result['errors'], false); } else { Session::set_flash('success', 'User created.'); Response::redirect('./'); } } if (Input::post()) { $form->repopulate(); $result = Model_User::validate_registration($form, $auth); } $view->set('reg', $form->build(), false); $this->template->title = 'User » Register'; $this->template->content = $view; }
protected function __construct($fieldset) { if ($fieldset instanceof Fieldset) { $fieldset->validation($this); $this->fieldset = $fieldset; } else { $this->fieldset = \Fieldset::forge($fieldset, array('validation_instance' => $this)); } $this->callables = array($this); $this->global_input_fallback = \Config::get('validation.global_input_fallback', true); }
/** * フリマ出店形態情報のフィールドセットを生成する * * @access private * @param * @return void * @author kobayashi */ private function createFieldsetFleamarketEntryStyles() { $entry_styles = \Config::get('master.entry_styles'); $fieldsets = array(); foreach ($entry_styles as $id => $entry_stype) { $fieldset = \Fieldset::forge("fleamarket_entry_style_{$id}"); if (isset($this->fleamarket_entry_styles[$id])) { $fieldset->add_model($this->fleamarket_entry_styles[$id])->populate($this->fleamarket_entry_styles[$id], false); } else { $fieldset->add_model('Model_Fleamarket_Entry_Style'); } if (Input::method() == 'POST') { $fields = array('booth_fee', 'max_booth', 'reservation_booth_limit'); foreach ($fields as $field) { $fieldset->field($field)->set_value(Input::post("fleamarket_entry_style_{$id}_{$field}")); } } $fieldsets[$id] = $fieldset; } return $fieldsets; }
/** * Enable or disable the tabular form feature of this fieldset * * @param string Model on which to define the tabular form * @param string Relation of the Model on the tabular form is modeled * @param array Collection of Model objects from a many relation * @param int Number of empty rows to generate * * @return Fieldset this, to allow chaining */ public function set_tabular_form($model, $relation, $parent, $blanks = 1) { // make sure our parent is an ORM model instance if (!$parent instanceof \Orm\Model) { throw new \RuntimeException('Parent passed to set_tabular_form() is not an ORM model object.'); } // validate the model and relation // fetch the relations of the parent model $relations = call_user_func(array($parent, 'relations')); if (!array_key_exists($relation, $relations)) { throw new \RuntimeException('Relation passed to set_tabular_form() is not a valid relation of the ORM parent model object.'); } // check for compound primary keys try { // fetch the relations of the parent model $primary_key = call_user_func($model . '::primary_key'); // we don't support compound primary keys if (count($primary_key) !== 1) { throw new \RuntimeException('set_tabular_form() does not supports models with compound primary keys.'); } // store the primary key name, we need that later $primary_key = reset($primary_key); } catch (\Exception $e) { throw new \RuntimeException('Unable to fetch the models primary key information.'); } // store the tabular form class name $this->tabular_form_model = $model; // and the relation on which we model the rows $this->tabular_form_relation = $relation; // load the form config if not loaded yet \Config::load('form', true); // load the config for embedded forms $this->set_config(array('form_template' => \Config::get('form.tabular_form_template', "<table>{fields}</table>\n"), 'field_template' => \Config::get('form.tabular_field_template', "{field}"))); // add the rows to the tabular form fieldset foreach ($parent->{$relation} as $row) { // add the row fieldset to the tabular form fieldset $this->add($fieldset = \Fieldset::forge($this->tabular_form_relation . '_row_' . $row->{$primary_key})); // and add the model fields to the row fielset $fieldset->add_model($model, $row)->set_fieldset_tag(false); $fieldset->set_config(array('form_template' => \Config::get('form.tabular_row_template', "<table>{fields}</table>\n"), 'field_template' => \Config::get('form.tabular_row_field_template', "{field}"))); $fieldset->add($this->tabular_form_relation . '[' . $row->{$primary_key} . '][_delete]', '', array('type' => 'checkbox', 'value' => 1)); } // and finish with zero or more empty rows so we can add new data if (!is_numeric($blanks) or $blanks < 0) { $blanks = 1; } for ($i = 0; $i < $blanks; $i++) { $this->add($fieldset = \Fieldset::forge($this->tabular_form_relation . '_new_' . $i)); $fieldset->add_model($model)->set_fieldset_tag(false); $fieldset->set_config(array('form_template' => \Config::get('form.tabular_row_template', "<tr>{fields}</tr>"), 'field_template' => \Config::get('form.tabular_row_field_template', "{field}"))); $fieldset->add($this->tabular_form_relation . '_new[' . $i . '][_delete]', '', array('type' => 'checkbox', 'value' => 0, 'disabled' => 'disabled')); // no required rules on this row foreach ($fieldset->field() as $f) { $f->delete_rule('required', false)->delete_rule('required_with', false); } } return $this; }
/** * 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(); static $_tabular_rows = array(); $class = is_object($obj) ? get_class($obj) : $obj; if (is_null($fieldset)) { $fieldset = \Fieldset::instance($class); if (!$fieldset) { $fieldset = \Fieldset::forge($class); } } // is our parent fieldset a tabular form set? $tabular_form = is_object($fieldset->parent()) ? $fieldset->parent()->get_tabular_form() : false; // don't cache tabular form fieldsets if (!$tabular_form) { !array_key_exists($class, $_generated) and $_generated[$class] = array(); if (in_array($fieldset, $_generated[$class], true)) { return $fieldset; } $_generated[$class][] = $fieldset; } $primary_keys = is_object($obj) ? $obj->primary_key() : $class::primary_key(); $primary_key = count($primary_keys) === 1 ? reset($primary_keys) : false; $properties = is_object($obj) ? $obj->properties() : $class::properties(); if ($tabular_form and $primary_key and !is_object($obj)) { isset($_tabular_rows[$class]) or $_tabular_rows[$class] = 0; } foreach ($properties as $p => $settings) { if (\Arr::get($settings, 'skip', in_array($p, $primary_keys))) { continue; } if (isset($settings['form']['options'])) { foreach ($settings['form']['options'] as $key => $value) { is_array($value) or $settings['form']['options'][$key] = \Lang::get($value, array(), false) ?: $value; } } // field attributes can be passed in form key $attributes = isset($settings['form']) ? $settings['form'] : array(); // label is either set in property setting, as part of form attributes or defaults to fieldname $label = isset($settings['label']) ? $settings['label'] : (isset($attributes['label']) ? $attributes['label'] : $p); $label = \Lang::get($label, array(), false) ?: $label; // change the fieldname and label for tabular form fieldset children if ($tabular_form and $primary_key) { if (is_object($obj)) { $p = $tabular_form . '[' . $obj->{$primary_key} . '][' . $p . ']'; } else { $p = $tabular_form . '_new[' . $_tabular_rows[$class] . '][' . $p . ']'; } $label = ''; } // create the field and add validation rules $field = $fieldset->add($p, $label, $attributes); if (!empty($settings['validation'])) { foreach ($settings['validation'] as $rule => $args) { if (is_int($rule) and is_string($args)) { $args = array($args); } else { array_unshift($args, $rule); } call_fuel_func_array(array($field, 'add_rule'), $args); } } } // increase the row counter for tabular row fieldsets if ($tabular_form and $primary_key and !is_object($obj)) { $_tabular_rows[$class]++; } return $fieldset; }
/** * Fieldsetオブジェクトの生成 * * @access public * @param bool $is_admin 管理画面かどうか * @return array * @author ida * @author kobayasi */ public static function createFieldset($is_admin = false) { $fieldset = \Fieldset::forge('fleamarket'); $fieldset->add_model('Model_Fleamarket'); $fieldset->validation()->add_callable('Custom_Validation'); if (!$is_admin) { $fieldset->add('reservation_email_confirm')->add_rule('match_field', 'reservation_email'); } return $fieldset; }
/** * コメント登録フィールドセット * * @access public * @return Fieldsetオブジェクト */ public static function comment_regist() { $form = \Fieldset::forge('article_comment_form'); $form->form()->set_attribute('class', 'form form-horizontal'); $form->add('comment', 'コメント', array('type' => 'textarea', 'rows' => 5, 'class' => 'form-control', 'required'))->add_rule('required')->add_rule('min_length', 1)->add_rule('max_length', 5000); $form->add('image', '画像ファイル', array('type' => 'file')); $form->form()->add_csrf(); $form->add('submit', '', array('type' => 'submit', 'value' => '投稿', 'class' => 'btn btn-primary')); return $form; }
/** * フィールドセットを生成する * * @access private * @return Fieldsetオブジェクト */ private function createFieldset() { if ($this->location) { $fieldset = \Fieldset::forge('location'); $fieldset->add_model($this->location)->populate($this->location, true); } else { $fieldset = \Model_Location::createFieldset(true); } $fieldset->repopulate(); return $fieldset; }
/** * 掲示板新規登録・修正用フォーム作成 * @param type $board * @return type */ public function makeBBSRegistForm($board = null) { //Modelから投稿用フォームを取得 $bd = Model_Board::forge(); $postFormFieldSet = Fieldset::forge('newBBSForm'); $postFormFieldSet->add_model($bd); if ($board != null) { $postFormFieldSet->populate($board); } //処理内容追加 if ($board != null) { $postFormFieldSet->add('kind', '処理内容', array('type' => 'select', 'options' => array('修正' => ' 修正 ', '削除' => ' 削除 '))); } //CSRF対策用 $postFormFieldSet->add(Config::get('security.csrf_token_key'), '', array('type' => 'hidden', 'value' => Security::fetch_token())); //送信ボタン追加 $postFormFieldSet->add('submit', '<BR>', array('type' => 'submit', 'width' => 80, 'value' => '送信')); return $postFormFieldSet; }
/** * フィールドセットの作成 * * @access private * @param * @return object * @author kobayashi */ private function createFieldset() { if ($this->user) { $fieldset = Fieldset::forge('user'); $fieldset->add_model($this->user)->populate($this->user, true); } else { $fieldset = Model_User::createFieldset(true); } $fieldset->repopulate(); return $fieldset; }
public function action_register() { // create the registration fieldset $form = \Fieldset::forge('registerform'); // add a csrf token to prevent CSRF attacks $form->form()->add_csrf(); // and populate the form with the model properties $form->add_model('Model\\Auth_User'); // add the fullname field, it's a profile property, not a user property $form->add_after('fullname', __('login.form.fullname'), array(), array(), 'username')->add_rule('required'); // add a password confirmation field $form->add_after('confirm', __('login.form.confirm'), array('type' => 'password'), array(), 'password')->add_rule('required'); // make sure the password is required $form->field('password')->add_rule('required'); // and new users are not allowed to select the group they're in (duh!) $form->disable('group_id'); // since it's not on the form, make sure validation doesn't trip on its absence $form->field('group_id')->delete_rule('required')->delete_rule('is_numeric'); // fetch the oauth provider from the session (if present) $provider = \Session::get('auth-strategy.authentication.provider', false); // if we have provider information, create the login fieldset too if ($provider) { // disable the username, it was passed to us by the Oauth strategy $form->field('username')->set_attribute('readonly', true); // create an additional login form so we can link providers to existing accounts $login = \Fieldset::forge('loginform'); $login->form()->add_csrf(); $login->add_model('Model\\Auth_User'); // we only need username and password $login->disable('group_id')->disable('email'); // since they're not on the form, make sure validation doesn't trip on their absence $login->field('group_id')->delete_rule('required')->delete_rule('is_numeric'); $login->field('email')->delete_rule('required')->delete_rule('valid_email'); } // was the registration form posted? if (\Input::method() == 'POST') { // was the login form posted? if ($provider and \Input::post('login')) { // check the credentials. if (\Auth::instance()->login(\Input::param('username'), \Input::param('password'))) { // get the current logged-in user's id list(, $userid) = \Auth::instance()->get_user_id(); // so we can link it to the provider manually $this->link_provider($userid); // logged in, go back where we came from, // or the the user dashboard if we don't know \Response::redirect_back('dashboard'); } else { // login failed, show an error message Log::error(__('login.failure')); } } elseif (\Input::post('register')) { // validate the input $form->validation()->run(); // if validated, create the user if (!$form->validation()->error()) { try { // call Auth to create this user $created = \Auth::create_user($form->validated('username'), $form->validated('password'), $form->validated('email'), \Config::get('application.user.default_group', 1), array('fullname' => $form->validated('fullname'))); // if a user was created succesfully if ($created) { // inform the user // link new user $this->link_provider($created); // and go back to the previous page, or show the // application dashboard if we don't have any \Response::redirect_back('/'); } else { // oops, creating a new user failed? Log::error(__('login.account-creation-failed')); } } catch (\SimpleUserUpdateException $e) { // duplicate email address if ($e->getCode() == 2) { Log::error(__('login.email-already-exists')); } elseif ($e->getCode() == 3) { Log::error(__('login.username-already-exists')); } else { Log::error($e->getMessage()); } } } } // validation failed, repopulate the form from the posted data $form->repopulate(); } else { // get the auth-strategy data from the session (created by the callback) $user_hash = \Session::get('auth-strategy.user', array()); // populate the registration form with the data from the provider callback $form->populate(array('username' => \Arr::get($user_hash, 'nickname'), 'fullname' => \Arr::get($user_hash, 'name'), 'email' => \Arr::get($user_hash, 'email'))); } $form->add('register', '', array('type' => 'hidden', 'value' => '1')); $form->add('submit', '', array('type' => 'submit', 'value' => 'submit')); // pass the fieldset to the form, and display the new user registration view return \View::forge('login/registration')->set('form', $form->build(), false)->set('login', isset($login) ? $login : null, false); }
/** * パスワード変更用のFieldset * * @access public * @return void * @author shimma */ public function createFieldsetPassword() { $fieldset = \Session::get_flash('mypage.password.fieldset'); if (!$fieldset) { $fieldset = \Fieldset::forge('mypage.password'); $fieldset->add('password', 'Passowrd')->add_rule('required')->add_rule('min_length', '6')->add_rule('max_length', '50'); $fieldset->add('new_password', 'New Passowrd')->add_rule('required')->add_rule('min_length', '6')->add_rule('max_length', '50'); $fieldset->add('new_password2', 'New Passowrd2')->add_rule('required')->add_rule('match_field', 'new_password'); } $fieldset->repopulate(); return $fieldset; }
public function action_index() { //Model_Postオブジェクトを新規作成 $post = Model_Post::forge(); $post->user_id = 1; //県のセレクト用のオプション配列の作成 $prefectures = Model_Prefecture::find('all'); $pref_op = array(); foreach ($prefectures as $pref) { $pref_op[$pref->id] = $pref->name; } //カテゴリのチェックボックス用のオプション配列の作成 $categories = array('何かを学ぶ旅' => '何かを学ぶ旅', '温泉でゆったりする旅' => '温泉でゆったりする旅', 'テーマパーク・アミューズメントの旅' => 'テーマパーク・アミューズメントの旅', '大自然にふれる旅' => '大自然にふれる旅', '街並みを楽しむ旅' => '街並みを楽しむ旅', 'グルメな旅' => 'グルメな旅', '平和について考える旅' => '平和について考える旅'); //タグのチェックボックス用のオプション配列の作成 $config = array('path' => DOCROOT . DS . '/assets/img/uimg', 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')); //Fieldsetオブジェクトにモデルを登録 $fieldset = Fieldset::forge('fset', $config)->add_model('Model_Post'); //県名選択を登録 $fieldset->add_before('prefid', '県名', array('type' => 'select', 'options' => $pref_op), array('required', 'in_array' => $pref_op), 'place'); //カテゴリ選択を登録 $fieldset->add_before('category2', 'カテゴリ', array('type' => 'select', 'options' => $categories), array('required', 'in_array' => $categories), 'tag1'); //ファイルアップロードを登録 $fieldset->add_after('imagefile', '写真', array('type' => 'file'), array('required'), 'rating'); //$fieldset->field('imagefile')->set_attribute('form_attributes',array('enctype'=>'multipart/form-data')); //投稿ボタンを登録 $fieldset->add_after('submit', '', array('type' => 'submit', 'value' => '投稿'), array(), 'rating'); //モデルの値をFieldsetに登録 $fieldset->populate($post, true); //$form = $fieldset->form(); //$form['imagefile']->set_config('form_attributes', array('enctype'=>'multipart/form-data')); //POSTの場合は登録処理を行う if (Input::method() == 'POST') { //Validationの実行 if ($fieldset->validation()->run()) { if (Input::post('imagefile')) { Upload::process($config); if (Upload::is_valid()) { Upload::save(); $getfile = Upload::get_files(); $file = $getfile[0]['name']; } else { //ファイルがアップロードできなかったとき、メッセージをフラッシュセッションにセット Session::set_flash('uerr', 'ファイルが正しくアップできませんでした。'); //投稿を中断して入力画面へリダイレクト Response::redirect('members/postfieldset'); } } var_dump($file); exit; //Validationに成功したフィールドの読み込み $fields = $fieldset->validated(); //Model_Postオブジェクトの生成 $post = Model_Post::forge(); //Model_Postオブジェクトのプロパティの設定 $post->user_id = $fields['user_id']; $post->pref_id = $fields['prefid']; $post->place = $fields['place']; $post->title = $fields['title']; $post->content = $fields['content']; $post->category = $fields['category2']; $post->tag1 = $fields['tag1']; $post->tag2 = $fields['tag2']; $post->rating = $fields['rating']; $post->image = $file; if ($post->save()) { Response::redirect('members/top'); } else { //入力エラーがある場合は元の入力画面にもどるため //入力した内容をそのまま引き継ぐ $fieldset->repopulate(); } } } //ビューの生成とbuild()したHTMLの埋め込み /* 本当は、members/postlist に飛びたい */ $view = View::forge('members/postfieldset'); $view->set('form', $fieldset->build(), false); return Response::forge($view); }
public function action_newRegist() { $msg = Session::get('errorMsg'); Session::delete('errorMsg'); $loginFieldSet = Fieldset::forge('loginForm'); $loginFieldSet->add('username', 'ユーザー名', array('type' => 'text', 'size' => 20)); $loginFieldSet->add('password', 'パスワード', array('type' => 'text', 'size' => 20)); $loginFieldSet->add('email_', 'E-Mail', array('type' => 'text', 'width' => 80)); $loginFieldSet->repopulate(); $this->setBoardTitle(); $dsc2 = <<<END <BR>\t\t\t\t <div id = 'article'> 新規ユーザー登録を行います。<BR> フォームに入力後、登録したメールアドレス宛てに確認メールが届きます。<BR> メールの文中のリンクをクリックすると、登録完了となります。<BR> </div> END; $this->template->set('boardDescription2', $dsc2, false); //CSRF対策用 $loginFieldSet->add(Config::get('security.csrf_token_key'), '', array('type' => 'hidden', 'value' => Security::fetch_token())); //送信ボタン追加 $loginFieldSet->add('submit', '投稿', array('type' => 'submit', 'width' => 80, 'value' => ' 送信 ')); $content = View::forge('index/newregist'); $content->set('loginForm', $loginFieldSet->build('index/newUser'), false); //エラーメッセージ設定 if ($msg != null) { $content->set('msg', $msg, false); } //no follow $this->template->nofollow = true; $this->template->content = $content; }