summaryrefslogtreecommitdiff
path: root/modules/forge/controllers/forge_demo.php
blob: 0fdedd97b1d53991f9274a71f25fdd52afb6c810 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
 * Forge module demo controller. This controller should NOT be used in production.
 * It is for demonstration purposes only!
 *
 * $Id$
 *
 * @package    Forge
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @license    http://kohanaphp.com/license.html
 */
class Forge_demo_Controller extends Controller {

	// Do not allow to run in production
	const ALLOW_PRODUCTION = FALSE;

	public function index()
	{
		$profiler = new Profiler;

		$foods = array
		(
			'tacos' => array('tacos', FALSE),
			'burgers' => array('burgers', FALSE),
			'spaghetti' => array('spaghetti (checked)', TRUE),
			'cookies' => array('cookies (checked)', TRUE),
		);

		$form = new Forge(NULL, 'New User');

		// Create each input, following this format:
		//
		//   type($name)->attr(..)->attr(..);
		//
		$form->hidden('hideme')->value('hiddenz!');
		$form->input('email')->label(TRUE)->rules('required|valid_email');
		$form->input('username')->label(TRUE)->rules('required|length[5,32]');
		$form->password('password')->label(TRUE)->rules('required|length[5,32]');
		$form->password('confirm')->label(TRUE)->matches($form->password);
		$form->checkbox('remember')->label('Remember Me');
		$form->checklist('foods')->label('Favorite Foods')->options($foods)->rules('required');
		$form->dropdown('state')->label('Home State')->options(locale_US::states())->rules('required');
		$form->dateselect('birthday')->label(TRUE)->minutes(15)->years(1950, date('Y'));
		$form->submit('save')->value('Save');

		if ($form->validate())
		{
			echo Kohana::debug($form->as_array());
		}

		echo $form->render();

		// Using a custom template:
		// echo $form->render('custom_view', TRUE);
		// Inside the view access the inputs using $input_id->render(), ->label() etc
		//
		// To get the errors use $input_id_errors.
		// Set the error format with $form->error_format('<div>{message}</div>');
		// Defaults to <p class="error">{message}</p>
		//
		// Examples:
		//   echo $username->render(); echo $password_errors;
	}

	public function upload()
	{
		$profiler = new Profiler;

		$form = new Forge;
		$form->input('hello')->label(TRUE);
		$form->upload('file', TRUE)->label(TRUE)->rules('required|size[200KB]|allow[jpg,png,gif]');
		$form->submit('upload')->value('Upload');

		if ($form->validate())
		{
			echo Kohana::debug($form->as_array());
		}

		echo $form->render();
	}

} // End Forge Demo Controller