From: avl Date: Wed, 10 Sep 2008 02:19:00 +0000 (+0300) Subject: Remove Ability for input fields X-Git-Tag: 0.5~498 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=44021c1921dfc9d22148bc052de85a03b73271cf;p=ipf.git Remove Ability for input fields --- diff --git a/ipf/form/field/file.php b/ipf/form/field/file.php index b38bb56..d7cb36a 100644 --- a/ipf/form/field/file.php +++ b/ipf/form/field/file.php @@ -4,11 +4,20 @@ class IPF_Form_Field_File extends IPF_Form_Field { public $widget = 'IPF_Form_Widget_FileInput'; public $move_function = 'IPF_Form_Field_moveToUploadFolder'; + public $remove_function = 'IPF_Form_Field_removeFile'; public $max_size = 2097152; // 2MB public $move_function_params = array(); function clean($value) { + if ($value['remove']==1){ + //print_r($value); + IPF::loadFunction($this->remove_function); + return call_user_func($this->remove_function, $value['data']); + } + + $value = $value['data']; + if ($value['name']=='') return ''; @@ -49,6 +58,7 @@ class IPF_Form_Field_File extends IPF_Form_Field } } + function IPF_Form_Field_moveToUploadFolder($value, $params=array()) { $name = IPF_Utils::cleanFileName($value['name']); @@ -63,3 +73,21 @@ function IPF_Form_Field_moveToUploadFolder($value, $params=array()) @chmod($dest, 0666); return $name; } + + +function IPF_Form_Field_removeFile($value, $params=array()) +{ + /* + $name = IPF_Utils::cleanFileName($value['name']); + $upload_path = IPF::get('upload_path', '/tmp'); + if (isset($params['upload_path'])) { + $upload_path = $params['upload_path']; + } + $dest = $upload_path.DIRECTORY_SEPARATOR.$name; + if (!move_uploaded_file($value['tmp_name'], $dest)) { + throw new IPF_Exception_Form(__('An error occured when upload the file. Please try to send the file again.')); + } + @chmod($dest, 0666); + */ + return null; +} diff --git a/ipf/form/widget/fileinput.php b/ipf/form/widget/fileinput.php index 0fcbfd9..c28c8b3 100644 --- a/ipf/form/widget/fileinput.php +++ b/ipf/form/widget/fileinput.php @@ -7,14 +7,21 @@ class IPF_Form_Widget_FileInput extends IPF_Form_Widget_Input public function render($name, $value, $extra_attrs=array()) { + $value = $value['data']; + $sim = ''; + if (is_string($value) && $value!=''){ + $sim = 'Currently: '.$value.' |
Change:'; + } $value = ''; - return parent::render($name, $value, $extra_attrs); + return $sim.parent::render($name, $value, $extra_attrs); } public function valueFromFormData($name, $data) { if (isset($data[$name])) { - return $data[$name]; + $remove = (int)$data[$name.'_remove']; + $res = array('data'=>$data[$name], 'remove'=>$remove); + return $res; } return null; } diff --git a/ipf/form/widget/image.php b/ipf/form/widget/image.php index e2c3040..6944954 100644 --- a/ipf/form/widget/image.php +++ b/ipf/form/widget/image.php @@ -2,12 +2,4 @@ class IPF_Form_Widget_Image extends IPF_Form_Widget_FileInput { - public function render($name, $value, $extra_attrs=array()) - { - $sim = ''; - if ($value!='') - $sim = 'Currently: '.$value.'
Change:'; - $value = ''; - return $sim.parent::render($name, $value, $extra_attrs); - } } \ No newline at end of file diff --git a/ipf/orm/record.php b/ipf/orm/record.php index fd81dcc..ff44338 100644 --- a/ipf/orm/record.php +++ b/ipf/orm/record.php @@ -1262,7 +1262,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab foreach ($cleaned_values as $key=>$val) { $validators = $this->getTable()->getFieldValidators($key); if (array_key_exists('image',$validators) || array_key_exists('file',$validators)){ - if ($val=='') + if (($val!==null) && ($val=='')) continue; } $this->$key = $val;