Changeset 3293 for trunk/application
- Timestamp:
- 08/07/2008 12:51:06 PM (4 months ago)
- Files:
-
- 1 modified
-
trunk/application/controllers/examples.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/application/controllers/examples.php
r3080 r3293 114 114 115 115 /** 116 * Demonstrates how to use the form helper with the Validation library .116 * Demonstrates how to use the form helper with the Validation libraryfor file uploads . 117 117 */ 118 118 function form() 119 119 { 120 $validation = new Validation; 121 122 echo form::open('', array('enctype' => 'multipart/form-data')); 123 120 // Anything submitted? 121 if ($_POST) 122 { 123 // Merge the globals into our validation object. 124 $post = Validation::factory(array_merge($_POST, $_FILES)); 125 126 // Ensure upload helper is correctly configured, config/upload.php contains default entries. 127 // Uploads can be required or optional, but should be valid 128 $post->add_rules('imageup1', 'upload::required', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[1M]'); 129 $post->add_rules('imageup2', 'upload::required', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[1M]'); 130 131 // Alternative syntax for multiple file upload validation rules 132 //$post->add_rules('imageup.*', 'upload::required', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[1M]'); 133 134 if ($post->validate() ) 135 { 136 // It worked! 137 // Move (and rename) the files from php upload folder to configured application folder 138 upload::save('imageup1'); 139 upload::save('imageup2'); 140 echo 'Validation successfull, check your upload folder!'; 141 } 142 else 143 { 144 // You got validation errors 145 echo '<p>validation errors: '.var_export($post->errors(), TRUE).'</p>'; 146 echo Kohana::debug($post); 147 } 148 } 149 150 // Display the form 151 echo form::open('examples/form', array('enctype' => 'multipart/form-data')); 124 152 echo form::label('imageup', 'Image Uploads').':<br/>'; 125 echo form::upload('imageup[]').'<br/>'; 126 echo form::upload('imageup[]').'<br/>'; 127 echo form::upload('imageup[]').'<br/>'; 153 // Use discrete upload fields 154 // Alternative syntax for multiple file uploads 155 // echo form::upload('imageup[]').'<br/>'; 156 157 echo form::upload('imageup1').'<br/>'; 158 echo form::upload('imageup2').'<br/>'; 128 159 echo form::submit('upload', 'Upload!'); 129 130 160 echo form::close(); 131 161 132 if ( ! empty($_POST))133 {134 $validation->set_rules('imageup', 'required|upload[gif,png,jpg,500K]', 'Image Upload');135 echo '<p>validation result: '.var_export($validation->run(), TRUE).'</p>';136 }137 138 echo Kohana::debug($validation);139 echo Kohana::lang('core.stats_footer');140 162 } 141 163 … … 249 271 { 250 272 $db = new Database; 251 273 252 274 $table = 'pages'; 253 275 echo 'Does the '.$table.' table exist? ';
