| 1 |
<?php defined('SYSPATH') or die('No direct script access.'); |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
class Forge_demo_Controller extends Controller { |
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
const ALLOW_PRODUCTION = FALSE; |
|---|
| 17 |
|
|---|
| 18 |
public function index() |
|---|
| 19 |
{ |
|---|
| 20 |
$profiler = new Profiler; |
|---|
| 21 |
|
|---|
| 22 |
$foods = array |
|---|
| 23 |
( |
|---|
| 24 |
'tacos' => array('tacos', FALSE), |
|---|
| 25 |
'burgers' => array('burgers', FALSE), |
|---|
| 26 |
'spaghetti' => array('spaghetti (checked)', TRUE), |
|---|
| 27 |
'cookies' => array('cookies (checked)', TRUE), |
|---|
| 28 |
); |
|---|
| 29 |
|
|---|
| 30 |
$form = new Forge(NULL, 'New User'); |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
// |
|---|
| 34 |
// type($name)->attr(..)->attr(..); |
|---|
| 35 |
// |
|---|
| 36 |
$form->hidden('hideme')->value('hiddenz!'); |
|---|
| 37 |
$form->input('email')->label(TRUE)->rules('required|valid_email'); |
|---|
| 38 |
$form->input('username')->label(TRUE)->rules('required|length[5,32]'); |
|---|
| 39 |
$form->password('password')->label(TRUE)->rules('required|length[5,32]'); |
|---|
| 40 |
$form->password('confirm')->label(TRUE)->matches($form->password); |
|---|
| 41 |
$form->checkbox('remember')->label('Remember Me'); |
|---|
| 42 |
$form->checklist('foods')->label('Favorite Foods')->options($foods)->rules('required'); |
|---|
| 43 |
$form->dropdown('state')->label('Home State')->options(locale_US::states())->rules('required'); |
|---|
| 44 |
$form->dateselect('birthday')->label(TRUE)->minutes(15)->years(1950, date('Y')); |
|---|
| 45 |
$form->submit('Save'); |
|---|
| 46 |
|
|---|
| 47 |
if ($form->validate()) |
|---|
| 48 |
{ |
|---|
| 49 |
echo Kohana::debug($form->as_array()); |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
echo $form->render(); |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
// echo $form->render('custom_view', TRUE); |
|---|
| 56 |
// Inside the view access the inputs using $input_id->render(), ->label() etc |
|---|
| 57 |
// |
|---|
| 58 |
// To get the errors use $input_id_errors. |
|---|
| 59 |
// Set the error format with $form->error_format('<div>{message}</div>'); |
|---|
| 60 |
// Defaults to <p class="error">{message}</p> |
|---|
| 61 |
// |
|---|
| 62 |
// Examples: |
|---|
| 63 |
// echo $username->render(); echo $password_errors; |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
public function upload() |
|---|
| 67 |
{ |
|---|
| 68 |
$profiler = new Profiler; |
|---|
| 69 |
|
|---|
| 70 |
$form = new Forge; |
|---|
| 71 |
$form->input('hello')->label(TRUE); |
|---|
| 72 |
$form->upload('file', TRUE)->label(TRUE)->rules('required|size[200KB]|allow[jpg,png,gif]'); |
|---|
| 73 |
$form->submit('Upload'); |
|---|
| 74 |
|
|---|
| 75 |
if ($form->validate()) |
|---|
| 76 |
{ |
|---|
| 77 |
echo Kohana::debug($form->as_array()); |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
echo $form->render(); |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
} |
|---|
| 84 |
|
|---|