本文整理汇总了PHP中Fieldset::forge方法的典型用法代码示例。如果您正苦于以下问题:PHP Fieldset::forge方法的具体用法?PHP Fieldset::forge怎么用?PHP Fieldset::forge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fieldset
的用法示例。
在下文中一共展示了Fieldset::forge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_regist
/**
* ユーザ登録
*
* @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;
}
示例2: action_create
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');
}
示例3: createFieldset
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;
}
示例4: forge_form
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;
}
示例5: test_for_in_label
/**
* 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);
}
示例6: createFieldset
/**
* ログイン用の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;
}
示例7: test_for_in_label
/**
* 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);
}
示例8: action_add
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));
}
示例9: post_register
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('./');
}
示例10: __construct
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);
}
}
示例11: action_add
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);
}
示例12: form
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;
}
示例13: before
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;
}
示例14: set_fields
/**
* 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;
}
示例15: set_fields
/**
* 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;
}