Changeset 740
- Timestamp:
- 08/24/08 10:46:59 (3 months ago)
- Files:
-
- trunk/lib/AjaxFileUploader.php (modified) (3 diffs)
- trunk/lib/Form/Field.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/AjaxFileUploader.php
r737 r740 4 4 * There is the only way I've found to do this: through IFrames. 5 5 * The example I used as a basement is on the http://web-tec.info/2007/09/09/ajax_fundamentals_iframe/ 6 * 6 * 7 7 * Usage: 8 8 * 1) Form which would upload file through Ajax should NOT be submitted by submitForm(), 9 9 * use Ajax::uploadFile() instead: 10 * 10 * 11 11 * $form->addButton('Submit')->uploadFile($form,$form->getElement('file')->name); 12 12 * 2) AjaxFileUploader class will be created and used to handle file upload. You can configure 13 13 * directory where uploaded files will be stored in config file 14 * 14 * 15 15 * $config['ajax_uploads_dir']='/uploads'; 16 16 * uploads/ dir in project root will be used by default. 17 17 * 3) You can reach uploaded file by calling: 18 * 18 * 19 19 * $file=$this->api->getElement('uploader')->getFile(); 20 20 * $file_path=$this->api->getElement('uploader')->getFilePath(); 21 21 * 4) Form is submitted from upload JS code after file is uploaded 22 * 22 * 23 23 * Ajax uploads use JS script functions from the ajax.js: 24 24 * createIFrame() 25 25 * submitUpload() 26 26 * sendComplete() 27 * 27 * 28 28 * If no file specified in the form, nothing done and form is simply submitted 29 * 29 * 30 30 * You may upgrade and improve this class on your own, probably it is not the best implementation. 31 * 31 * 32 32 * Created on 21.06.2008 by *Camper* (camper@adevel.com) 33 33 */ … … 35 35 protected $file_path=''; 36 36 protected $mime_type=null; 37 37 38 38 function init(){ 39 39 parent::init(); … … 48 48 } 49 49 function getFilePath(){ 50 return $this->file_path; 50 if(!$this->file_path)return ''; 51 return (defined('BASEDIR')?BASEDIR.'/':'').$this->file_path; 51 52 } 52 53 function setFilePath($path){ trunk/lib/Form/Field.php
r736 r740 142 142 $this->template->trySet('field_caption',$this->caption?($this->caption.$this->separator):''); 143 143 $this->template->trySet('field_name',$this->name); 144 $this->template->trySet('field_comment',$this->comment); 145 $this->template->set('field_input',$this->field_prepend.$this->getInput().$this->field_append); 144 $this->template->trySet('field_comment',$this->comment); 145 $this->template->set('field_input',$this->field_prepend.$this->getInput().$this->field_append); 146 146 $this->template->trySet('field_error', 147 147 isset($this->owner->errors[$this->short_name])? … … 217 217 * --> <a href="foo.html"><b>click here</b></a> 218 218 */ 219 219 220 220 if(is_string($attr)){ 221 221 $value=$attr; … … 302 302 $this->setNoSave(); 303 303 } 304 304 305 305 function getInput($attr=array()){ 306 306 if (isset($this->value_list)){ … … 313 313 $this->value_list = $list; 314 314 } 315 315 316 316 } 317 317 class Form_Field_File extends Form_Field { … … 326 326 $this->name=$this->short_name='MAX_FILE_SIZE'; 327 327 parent::init(); 328 $this->no_save=true; 328 329 } 329 330 } 330 331 class Form_Field_Time extends Form_Field { 331 332 function getInput($attr=array()){ 332 return parent::getInput(array_merge(array('type'=>'text', 333 return parent::getInput(array_merge(array('type'=>'text', 333 334 'value'=>format_time($this->value)),$attr)); 334 335 } … … 337 338 private $sep = '-'; 338 339 private $is_valid = false; 339 340 340 341 /*function getInput($attr=array()){ 341 return parent::getInput(array_merge(array('type'=>'text', 342 return parent::getInput(array_merge(array('type'=>'text', 342 343 'value'=>($this->is_valid ? date('Y-m-d', $this->value) : $this->value)),$attr)); 343 344 }*/ … … 357 358 $c = split($this->sep, $this->value); 358 359 //day must go first, month should be second and a year should be last 359 if(strlen($c[0]) != 4 || 360 $c[1] <= 0 || $c[1] > 12 || 360 if(strlen($c[0]) != 4 || 361 $c[1] <= 0 || $c[1] > 12 || 361 362 $c[2] <= 0 || $c[2] > 31) 362 363 { … … 381 382 } 382 383 function getInput($attr=array()){ 383 384 384 385 // Disable the deny edit here < 385 386 if (is_null($this->onkeypress)) { 386 387 $this->onKeyPress(); 387 388 } 388 389 return 389 390 return 390 391 parent::getInput(array_merge(array(''=>'textarea'),$attr)). 391 392 htmlspecialchars(stripslashes($this->value)). … … 399 400 } 400 401 401 // The following clases operates with predefined value lists. 402 // The following clases operates with predefined value lists. 402 403 // User is picking one or several options 403 404 class Form_Field_ValueList extends Form_Field { … … 426 427 } else { 427 428 if(isset($_POST[$this->name]))$this->set($data); 428 } 429 } 429 430 } 430 431 } … … 512 513 return $output; 513 514 } 514 515 515 516 function loadPOST(){ 516 517 $data=$_POST[$this->name]; 517 518 if(is_array($data)) 518 519 $data=join(',',$data); 519 else 520 else 520 521 $data=''; 521 522 … … 525 526 } else { 526 527 $this->set($data); 527 } 528 } 528 } 529 } 529 530 } 530 531
