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.

Data Model Questions /

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

HTMLText Saving Error


Go to End


5 Posts   2546 Views

Avatar
Eurisko

Community Member, 27 Posts

24 July 2015 at 8:30pm

I have a data object with the code

<?php
    class HeroBannerImage extends DataObject {
        private static $db = array (
            'Name' => 'varchar',
            'Duration' => 'int',
            'Message' => 'HTMLText'
        );

        private static $has_one = array (
            'Banner' => 'HeroBanner',
            'Img' => 'Image'
        );

        public function getCMSfields()
        {
            $fields = FieldList::create(
                TextField::create( 'Name' ),
                HTMLEditorField::create( 'Message' ),
                DropdownField::create( 'Duration' )
                    ->setSource( ArrayLib::valuekey( range( 5, 20 ) ) ),
                $upload = UploadField::create( 'Img', 'Upload or select an image' )
            );

            $upload->getValidator()->setAllowedExtensions(array(
                'png', 'jpeg', 'jpg', 'gif'
            ));
            $upload->setFolderName('hero-images');

            return $fields;
        }

    }

When I click save in the CMS I get an ambigious error that makes me dig around in the framework code. When I find the line the error refers to I find

/framework/forms/HtmlEditorField.php

		if($record->hasField($this->name) && $record->escapeTypeForField($this->name) != 'xml') {
			throw new Exception (
				'HtmlEditorField->saveInto(): This field should save into a HTMLText or HTMLVarchar field.'
			);
		}

Could someone point me in the direction as to what this error means. The Message field *is* a HTMLText field.

Thanks

Avatar
Pyromanik

Community Member, 419 Posts

24 July 2015 at 10:07pm

Looks like you forgot to flush or build after updating your model to match the recommendation in the error message.

Avatar
Eurisko

Community Member, 27 Posts

24 July 2015 at 10:15pm

Hi Pyromanik.

Thanks for the response. Unfortunately building and flushing was the first thing I tried when it wasn't working. The problem is still there.

Avatar
Eurisko

Community Member, 27 Posts

24 July 2015 at 11:05pm

okay I solved it, bit of an odd one. I changed the field to HTMLVarchar, built and flushed, same problem, then changed it back to HTMLText, built and flushed, problem gone.

Avatar
Rob Clarkson

Community Member, 26 Posts

10 March 2016 at 9:33am

I've also got this issue, appears to happen for non administrators who have correct access permissions anyway. I've tried your fix however and I'm still getting this issue.