Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Force Unique Filename for UploadField in Userforms


Go to End


686 Views

Avatar
tazzydemon

Community Member, 135 Posts

6 August 2014 at 12:17pm

Edited: 06/08/2014 12:24pm

I have added a field type in my userforms module so that i have a modern uploadfield with drag and drop.

To do this I simply took a copy of the original editablefilefield and modified the "new FileField" to "new Uploadfield".

A few other settings were added to prevent user meddling with files, plus I set the folder.

It all works well - or seems to, but there is a snag. The uploads have been completed on a form that has not yet been submitted and so has no ID of any sort. The uploaded images(actually there may be four instances in this form), have to be unique but hopefully with names that superficially bear some resemblance to the ones the users uploads. I cant use the form ID, so how can I make the UploadField produce unique names?

I have a field on the form (don't forget it's a userform) that has a customer id. This could be used as a prefix. I fear I am getting into custom form territory here. Maybe I could add a field in the CMS to pull the data from another field. But even this has a snag. They might upload the images first! Back to random prefix....

Julian