Etable/formType/file
出自六年制學程
目錄
(一)製作表單元素類別
formsome.php 中
class XoopsFormUploadFile extends XoopsFormElement { function XoopsFormUploadFile($caption, $name){ // 提示、後傳變數名 $this->setCaption($caption); $this->setName($name); } function render(){ return "<input type='file' name='".$this->getName()."' id='".$this->getName()."'".$this->getExtra()." />".$this->getExtra('2'); } } class XoopsFormFile extends XoopsFormElementTray{ function XoopsFormFile($caption, $name, $value='', $paths=array('.'=>'當前路徑')){ $this->XoopsFormElementTray($caption,' '); $pathSelect=new XoopsFormSelect('路徑:',$name.'[path]',$value='');// 產生選單物件並指定預選值 $pathSelect->addOptionArray($paths); $this->addElement($pathSelect);// 將選單物件放入表單 $fileUpload=new XoopsFormUploadFile('請選檔:', $name.'[fileName]'); $this->addElement($fileUpload);// 將選單物件放入表單 } }
(二)addElements($i,$value)
加表單元素類型為 file 則$j=new XoopsFormFile($this->fields[$i]['colalias'],'f['.$this->fields[$i]['as_name'].']['.$this->fields[$i]['colname'].']',str_replace("'",''',str_replace("&",'&',$value)),$this->formType["$lc_name"][1]['paths']); $this->form->addElement($j,(($this->fields[$i]['formValidate']==0)?'0':'1')); $this->form->addElement(new XoopsFormHidden('uploadFileField',$lc_name,0)); $this->form->addElement(new XoopsFormHidden('uploadFilePath',$value,0));