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.

Customising the CMS /

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

One variable for multi UploadField validation


Go to End


1288 Views

Avatar
eightythree

Community Member, 12 Posts

20 March 2016 at 1:21am

Hi there,
is there possible (if so, how to write it) to declare one variable for two (or more) upload fields ? Sorry if naming is wrong, I'm not a programmer.

For example, something like that:

$fields->addFieldToTab('Root.Download Area', $BulkFilesFirst = UploadField::create('First'));
$fields->addFieldToTab('Root.Download Area', $BulkFilesSecond = UploadField::create('Second'));

$BulkFilesFirst->setFolderName('some folder');
$BulkFilesFirst->getValidator()->setAllowedExtensions(array('pdf', 'zip'));

$BulkFilesSecond->setFolderName('some folder');
$BulkFilesSecond->getValidator()->setAllowedExtensions(array('pdf', 'zip'));

into:

$fields->addFieldToTab('Root.Download Area', $BulkFiles = UploadField::create('First'));
$fields->addFieldToTab('Root.Download Area', $BulkFiles = UploadField::create('Second'));

$BulkFiles->setFolderName('some folder');
$BulkFiles->getValidator()->setAllowedExtensions(array('pdf', 'zip'));

I know that code wouldn't work as I want (but you get the idea). Any help would be appreciated.

Thanks for your time,
Darek.