Changeset 1653

Show
Ignore:
Timestamp:
01/01/08 19:35:57 (6 months ago)
Author:
Shadowhand
Message:

Couple of quick changes:

  • Added comma to the default allowed URI characters
  • Updated forge_demo with an upload demo (not functional)
  • Started outlining some more rules in Form_Upload
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/modules/forge/controllers/forge_demo.php

    r1522 r1653  
    77                $profiler = new Profiler; 
    88 
    9                 $foods = array( 
    10                         'taco' => FALSE, 
    11                         'burger' => FALSE, 
    12                         'spaghetti (checked)' => TRUE, 
    13                         'cookies (checked)' => TRUE); 
     9                $foods = array 
     10                ( 
     11                        'tacos' => array('tacos', FALSE), 
     12                        'burgers' => array('burgers', FALSE), 
     13                        'spaghetti' => array('spaghetti (checked)', TRUE), 
     14                        'cookies' => array('cookies (checked)', TRUE), 
     15                ); 
    1416 
    1517                $form = new Forge(NULL, 'New User'); 
     
    3840        } 
    3941 
    40         public function edit_user($id = FALSE
     42        public function upload(
    4143        { 
    4244                $profiler = new Profiler; 
    43                 $cache = new Cache; 
    4445 
    45                 // Cache id for the current empty editing form 
    46                 $cache_id = 'form--'.url::current(); 
     46                $form = new Forge; 
     47                $form->upload('file')->label(TRUE)->rules('allow[jpg,png,gif]|size[2M]'); 
     48                $form->submit('Upload'); 
    4749 
    48                 if (empty($_POST)) 
     50                if ($form->validate()) 
    4951                { 
    50                         // Attempt to get the HTML from cache 
    51                         if ($form = $cache->get($cache_id)) 
    52                         { 
    53                                 echo $form; 
    54                                 return; 
    55                         } 
     52 
    5653                } 
    5754 
    58                 // Create a new user editing form 
    59                 $form = new User_Edit_Model(NULL, 'Edit User', $id); 
    60  
    61                 if ($form->save()) 
    62                 { 
    63                         // Cache information is no longer valid 
    64                         $cache->del($cache_id); 
    65  
    66                         echo Kohana::debug('user edited!', $form->as_array()); 
    67                 } 
    68  
    69                 if (empty($_POST)) 
    70                 { 
    71                         // Cache the form HTML 
    72                         $cache->set($cache_id, $form = $form->html()); 
    73                 } 
    74  
    75                 echo $form; 
     55                echo $form->html(); 
    7656        } 
    7757 
  • trunk/modules/forge/libraries/Form_Upload.php

    r1591 r1653  
    55        protected $data = array 
    66        ( 
    7                 'class' => 'upload' 
     7                'class' => 'upload', 
     8                'value' => '', 
    89        ); 
    910 
    10         protected $protect = array('type', 'label'); 
     11        protected $protect = array('type', 'label', 'value'); 
     12 
     13        public function __construct($name) 
     14        { 
     15                parent::__construct($name); 
     16 
     17                if ( ! empty($_FILES) AND ! empty($_FILES[$name])) 
     18                        $_POST[$name] = $_FILES[$name]; 
     19        } 
     20 
     21        public function rule_allow() 
     22        { 
     23                echo Kohana::debug(func_get_args()); 
     24 
     25                return TRUE; 
     26        } 
     27 
     28        public function rule_size($size) 
     29        { 
     30                echo Kohana::debug($size); 
     31 
     32                return TRUE; 
     33        } 
     34 
     35        public function load_value() 
     36        { 
     37                if (empty($_FILES)) 
     38                        return; 
     39 
     40                echo Kohana::debug($_FILES); 
     41        } 
    1142 
    1243        public function html() 
  • trunk/system/config/routes.php

    r1522 r1653  
    99 * Permitted URI characters. 
    1010 */ 
    11 $config['_allowed'] = 'a-z 0-9~%.:_-'; 
     11$config['_allowed'] = 'a-z 0-9~%.,:_-'; 
    1212 
    1313/**