File input problem
Hi,
I am using a snippet to give the ability to logged users to post and edit specific type resources via formit.
One of the fields of the formit form is a file input that is uploading as a tv field.
The problem is that when a user updates the resource and leave the file input field blank, when it saves, the blank input overwrite any previous inputs.
All I want is to make the snippet to ignore blank inputs only at the file input field.
If anynone can help. I am really stuck here.
Below is the code I use.
I am using a snippet to give the ability to logged users to post and edit specific type resources via formit.
One of the fields of the formit form is a file input that is uploading as a tv field.
The problem is that when a user updates the resource and leave the file input field blank, when it saves, the blank input overwrite any previous inputs.
All I want is to make the snippet to ignore blank inputs only at the file input field.
If anynone can help. I am really stuck here.
Below is the code I use.
<?php
if (isset($_GET['resId'])){
if ($doc=$modx->getObject('modResource',array('id'=>$_GET['resId']))){
$docarray=$doc->toArray();
$fields = explode(',',$scriptProperties['resource2formitfields']);
$fields[] = 'id';
foreach ($fields as $field){
if ($doc->getFieldName($field) === null) {
/* if field isnt defined, look for TV value */
$tvValue = $doc->getTVValue($field);
if ($tvValue !== null) {
$hook->setValue($field,$tvValue);
}
} else {
/* otherwise get field value */
$hook->setValue($field,$docarray[$field]);
}
}
}
//$errorMsg = '<pre>'.print_r($docarray,true).'</pre>';
//$hook->addError('error_message',$errorMsg);
}
return true; Комментарии: 4
Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
to
Looks little ugly but must work.
IMAGE is a tv field.
sorry for the late answer, but I was away of the office for some days. I tried the code you suggest me, but unfortunatule it didn't work. I tried some other code also, didn't worked either.
So I changed my approach and I am trying now to find a solution with ajaxupload.
There are problems with ajaxupload also since it can upload images to resource but I can't retrieve them to the queue when I edit.