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.

Form Questions /

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

multiple conditions in UploadField?


Go to End


1379 Views

Avatar
_Vince

Community Member, 165 Posts

9 May 2014 at 11:14am

I'm trying to check for two (or possibly more) conditions in an UploadField.

Basically, I want to allow some image types and make sure they're no bigger than 1Mb.

The problem is that all the examples I've seen only show ONE condition, ie the following does not work.

$LogoImageField = new UploadField('LogoImage');
$LogoImageField->getValidator()->allowedExtensions = array('jpg', 'gif', 'png', 'JPG', 'GIF', 'PNG');
$LogoImageField->getValidator()->setAllowedMaxFileSize(1048576);
$LogoImageField->setFolderName('LogoImages');

How can I rewrite this to have more than one condition?

Thanks in advance.