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

2.4x ImageField Validators. How to display error messages?


Go to End


631 Views

Avatar
Double-A-Ron

Community Member, 607 Posts

23 April 2013 at 10:29pm

I have this code inside function getCMSFields() for a page type to restrict image uploads to 1MB:

$image_validator = new Upload_Validator();
$image_validator->setAllowedMaxFileSize(1048576);
$photo1 = new ImageField('Photo1');
$photo1->setValidator($image_validator);
...
$fields->addFieldToTab( 'Root.Content.Images', $photo1 );

Seems to work just fine. The thing is when it fails, the CMS displays no explanation to the user. There also doesn't appear to be any action in Firebug.

Anyone know how to display a message to the user along the lines of "The file you tried to upload is too big"?