Giter Club home page Giter Club logo

fuelphp-fieldset's Introduction

Fuel Fieldset Package.

Overview

This Package provide Fieldset class for various layouts.

Installing

Simply add fieldset to your config.php always_loaded.packages config option.

Usage

class Fieldset_Sample extends \Fuel\Fieldset\Fieldset
{
	/**
	 * Create Fieldset object
	 *
	 * @param   string    $name    Identifier for this fieldset
	 * @param   array     $config  Configuration array
	 * @return  Fieldset
	 */
	public static function forge($name = null, array $config = array())
	{
		$fieldset = parent::forge(name, config);

		// add name
		$fieldset->add(
			'name',
			'Full name',
			array(
				'type' => 'name',
				'class' => 'pretty_input'
			),
			array(
				array(
					'required'
				),
				array(
					'valid_string',
					array(
						'alpha-numeric',
						'dots',
						'spaces'
					)
				)
			)
		);

	}
}
class Controller_Sample extends Controller
{
	/**
	 * Index Action
	 *
	 * @return  string
	 */
	public function action_index()
	{
		$fieldset = Fieldset_Sample::forge();

		$mode = Input::post('button');

		if ($mode === 'confirm')
		{
			// confirm
			$validation = $fieldset->validation();

			if ($validation->run())
			{
				// validation OK
				$fields = $validation->validated();

				// create view
				$view = Presenter::forge('sample/confirm');
				// set fields
				$view->set('fields', $fields);
				// show confirm view
				return Response::forge($view);
			}
			else
			{
				// validation NG

				// set input values
				$fieldset->repopulate();
			}
		}
		else if ($mode === 'exec')
		{
			// exec
			$validation = $fieldset->validation();

			if ($validation->run())
			{
				// validation OK
				$fields = $validation->validated();

				// Do Exec

				// redirect to complete
				Response::redirect('sample/complete', 'location', 303);

			}
			else
			{
				// validation NG

				// set input values
				$fieldset->repopulate();
			}
		}
		else if ($mode === 'back')
		{
			// back

			// set input values
			$fieldset->repopulate();
		}

		// create view
		$view = Presenter::forge('sample/input');
		// set fields
		$view->set_safe('fields', $fieldset->build_field());
		// show confirm view
		return Response::forge($view);
	}

	/**
	 * Complete Action
	 *
	 * @return  string
	 */
	public function action_complete()
	{
		// create view
		$view = Presenter::forge('sample/complete');
		// show complete view
		return Response::forge($view);
	}
}
// input view
<?php echo \Form::open().PHP_EOL; ?>
	<div class="form-group <?php echo \Arr::get($fields, 'name.error_class') ?>">
		<label>Full name</label>
		<?php echo \Arr::get($fields, 'name.field'); ?>
	</div>
	<button type="submit" class="btn btn-default" value="confirm">Confirm</button>
<?php echo \Form::close().PHP_EOL; ?>
// confirm view
<?php echo \Form::open().PHP_EOL; ?>
	<div class="form-group <?php echo \Arr::get($fields, 'name.error_class') ?>">
		<label>Full name</label>
		<?php echo \Arr::get($fields, 'name').PHP_EOL; ?>
		<?php echo \Form::hidden('name', \Arr::get($fields, 'name')).PHP_EOL; ?>
	</div>
	<button type="submit" class="btn btn-default" value="back">Back</button>
	<button type="submit" class="btn btn-default" value="exec">Submit</button>
<?php echo \Form::close().PHP_EOL; ?>

fuelphp-fieldset's People

Contributors

yuki-ohnaka-no4 avatar yuki0410-dev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.