Forums

File upload ghost value

emmexx 28 Apr, 2016
I'm not sure if I understand correctly how to use the Ghost value in a File Upload item.

I save the file name in a table field and I need to edit the records.

In the Ghost value text box I put {myname}.

When I reload a record it works ok.

The problem: the File upload field is not required. So {myname} (literal) is saved in the table even when I don't upload any file.

I'm confused.

Isn't the ghost value supposed to be used the way I'm using it?
Should I use php code instead?

Thank you
maxx
GreyHead 28 Apr, 2016
Hi maxx,

Please check this FAQ about editing file inputs. It's a little bit tricky.

Bob
emmexx 28 Apr, 2016
Thank you Bob, but I know how to manage editing. :-)

What I found unexpected is the behaviour of the syntax {myname}.
I expected that when there's no myname value defined in the form, just like when creating a new record in a form, {myname} would be blank. That is what happens elsewhere in CF.

Anyway I'll use a custom code.

Thank you
maxx
GreyHead 29 Apr, 2016
Hi Maxx,

Sorry, then I just don't understand what you are trying to do. If you add {myname} in the Ghost Value box then that is - I think - treated as a string and will be submitted if the File Field element is empty. It is then included in the $form->data array and will be saved along with the other form data - exactly as you describe. ChronoForms won't replace {myname} with another value in that context - though you could do so using Custom Code.

Bob
emmexx 29 Apr, 2016
Hi Bob,

my question is about the behaviour of CF5 when it finds somewhere {something}.
I expected {something} to be substituted by a value when there is on load $form->data['something'] = 'a value' and
I expected {something} to be substituted by blank when $form->data['something'] is not set or is an empty string. That is what happens to curly brackets elsewhere in CF.
But when I use the curly brackets as a ghost value (in a file upload action), my 1st expectation is correct, the second one is not. So what happens is that my form (with a new record, not an edit) is submitted with
$form->data['something'] = '{something}'

instead of
$form->data['something'] = ''

or
$form->data['something'] =

That is odd.

bye
maxx
GreyHead 29 Apr, 2016
Hi Maxx,

The {} syntax works in some places but not everywhere and apparently not in Ghost values. If you want an empty string then enabling the ghost and leaving the value empty should do that. But the result is probably the same as not using the Ghost value.

Bob
This topic is locked and no more replies can be posted.