lang/ja

<?php
return array(
		'required'           => ':labelは必須です',
		'max_length'         => ':labelは:param:文字以内で入力してください',
		'correct_yakushoku'  => ':labelが所属と合致しません',
		'only_one_yakushoku' => '部署の役職人数制限に反します',
);

classes/validation.php

<?php
/**
 * 拡張Validation
 * 一括設定
 * @package     Fuel
 * @subpackage  Core
 * @category    Core
 */
class Validation extends \Fuel\Core\Validation
{
	// 検証条件をまとめて指定
	public function add_fieldset($params = array(), $input = array())
	{
		var_dump('aaaaaa');
		// 入力データが空ならPOSTを設定
		if ( count($input) <= 0 )
		{
			$input = $_POST;
		}
		var_dump($params);
		// 検証条件セット
		if( is_array($params) )
		{
			foreach($params as $conf)
			{
				if ( strlen($conf['rules']) > 0 )
				{
					$this->add_field($conf['name'], $conf['label'], $conf['rules']);
				}
			}
			return true;
		}
		return false;
	}

	// エラーをまとめて取得
	public function get_messages()
	{
		$msg = array();
		foreach($this->error() as $field => $error)
		{
			$msg[$field] = $this->error($field)->get_message();
		}
		return $msg;
	}
}

config/validation.php

<?php
return array(
	'employee' => array(
			'family_name'  => array(
				'name'   => 'name',
				'label'  => '名字',
				'rules'  => 'required|max_length[15]',
			),
			'given_name'  => array(
				'name'   => 'given_name',
				'label'  => '名前',
				'rules'  => 'required|max_length[15]',
			),
			'phonetic_of_family_name'  => array(
				'name'   => 'phonetic_of_family_name',
				'label'  => '名字(カナ)',
				'rules'  => 'required|max_length[15]',
			),
			'phonetic_of_given_name'  => array(
				'name'   => 'phonetic_of_given_name',
				'label'  => '名前(カナ)',
				'rules'  => 'required|max_length[15]',
			),
			'bu'  => array(
				'name'   => 'bu',
				'label'  => '部',
				'rules'  => 'required',
			),
			'yakushoku'  => array(
				'name'   => 'yakushoku',
				'label'  => '役職',
				'rules'  => 'required|correct_yakushoku|only_one_yakushoku',
			),
	),
);

Model_Employee

<?php

class Model_Employee extends \Orm\Model
{
	protected static $_properties = array(
		'id',
		'family_name',
		'given_name',
		'phonetic_of_family_name',
		'phonetic_of_given_name',
		'affiliation_id',
		'position_id',
		'picture_url',
		'comments',
		'has_been_deleted',
		'number_of_editing',
	);

	protected static $_table_name = 'employee';
	protected static $_belongs_to = array(
		'affiliation' => array(
			'key_from' => 'affiliation_id',
			'model_to' => 'Model_Affiliation',
			'key_to' => 'id',
		),
		'position' => array(
			'key_from' => 'position_id',
			'model_to' => 'Model_Position',
			'key_to' => 'id',
		)
	);

	/**
	 * 人数制限バリデーション用
	 */
	public function get_count_column($affi, $yakushoku){
		$query = self::forge();
		$query->where('affiliation_id', $affi)
		->where('position_id', '>', $yakushoku)
		->count();
		return $query;
	}
}

Cont/Emplo

<?php

class Controller_Employee extends Controller_Template
{

	private $per_page = 3;

	public function action_index()
	{
		//ビューに渡す配列の初期化
		$data = array();

		//タイトル
		$this->template->title = '社員情報一覧';
		//ビューの読み込み
		$this->template->content = ViewModel::forge('employee/index.twig');

	}

	public function get_regist()
	{
		 self::post_validation();
		//タイトル
		$this->template->title = '社員情報一覧';
		//ビューの読み込み
		$this->template->content = ViewModel::forge('employee/regist.twig');

	}
	//確認画面から戻ってくる用
	public function post_regist()
	{
		self::post_validation();
		//タイトル
		$this->template->title = '社員情報一覧';
		//ビューの読み込み
		$this->template->content = ViewModel::forge('employee/regist.twig');

	}

	public function post_confirm()
	{
		$validation = self::post_validation();
		var_dump($validation);
		//タイトル
		$this->template->title = '社員情報一覧';
		//ビューの読み込み
		$view = ViewModel::forge('employee/confirm.twig');
		$view -> set('validation', $validation);
		$this->template->content = ViewModel::forge('employee/confirm.twig');

	}

	public static function post_validation()
	{
		// プロファイリング停止
		Fuel::$profiling = false;

		// json初期値
		$json = array(
			'res'   => 'NG',
			'error' => array(),
		);

		// バリデーション設定
		Config::load('validation', true);
		$val_config = Config::get('validation.employee');

		$val = Validation::forge();
		$val->add_callable('Extension');
		$val->add_fieldset($val_config);
		var_dump($val->run());

		// バリデーションチェック
		if ( $val->run() )
		{
			$json['res'] = 'OK';
			$json['error'] = null;
		}
		else
		{
			$json['error'] = $val->get_messages();
		}
		return $json['error'];
	}
}

View_Employee_Regist

<?php
class View_Employee_Regist extends ViewModel {
	public function view() {
		//確認画面からの入力値引継ぎ
		$result = Input::post();
		//プルダウン表示用
		$this->family_name             = Input::post('family_name', null);
		$this->given_name              = Input::post('given_name', null);
		$this->phonetic_of_family_name = Input::post('phonetic_of_family_name', null);
		$this->phonetic_of_given_name  = Input::post('phonetic_of_given_name', null);
		$this->bu          			   = Input::post('bu', null);
		$this->ka                      = Input::post('ka', null);
		$this->kakari                  = Input::post('kakari', null);
		$this->yakushoku               = Input::post('yakushoku', null);

		//プルダウン表示用
		$bu_obj        = DB::select ( 'department_name' )->from ( 'affiliation' )->distinct(true)->execute();
		$ka_obj        = DB::select ( 'section_name' )->from ( 'affiliation' )->distinct(true)->execute();
		$kakari_obj    = DB::select ( 'subsection_name' )->from ( 'affiliation' )->distinct(true)->execute();
		$yakushoku_obj = DB::select ( 'assigned_name' )->from ( 'position' )->distinct(true)->execute();

		foreach ($bu_obj as $key => $value) {
			$bu_list[] =$value;
		}
		foreach ($ka_obj as $key => $value) {
			$ka_list[] =$value;
		}
		foreach ($kakari_obj as $key => $value) {
			$kakari_list[] =$value;
		}
		foreach ($yakushoku_obj as $key => $value) {
			$yakushoku_list[] =$value;
		}
		$this->bu_list       = $bu_list;
		$this->ka_list       = $ka_list;
		$this->kakari_list   = $kakari_list;
		$this->yakushoku_list= $yakushoku_list;

	}
}