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.

Archive /

Our old forums are still available as a read-only archive.

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

Adding an image tab to a Contact Form


Go to End


4 Posts   1810 Views

Avatar
bones

Community Member, 110 Posts

26 September 2008 at 3:57am

I've added an "Images" tab to most of my pages, so that I can add an image that is also displayed in the Holder page enclosing it. I've done this in the following way:

Opening the page's .php file

Adding

static $has_one = array(
'Photo' => 'Image'
);

and

function getCMSFields($cms) {
$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo'));
return $fields;
}

as described in the tutorials. Works perfectly :)

However, I've tried to do the same in UserDefinedForm.php. It initially seems to work, but when I try to upload the image (or select one from the File Store) and click "attach image", it displays "ERROR. The website server has not been able to respond to your request."

Any help gratefully received.

Thanks

Avatar
Willr

Forum Moderator, 5523 Posts

26 September 2008 at 9:58pm

First thing is to get a proper error message by setting the site into 'development' mode by adding

Director::set_environment_type("dev");

to your mysite/_config.php file. This will give you a more useful message!

Avatar
Sean

Forum Moderator, 922 Posts

27 September 2008 at 12:49am

Edited: 27/09/2008 12:51am

I think the way you've added the getCMSFields() function could be the problem.

The way we usually do it is like this:


function getCMSFields() {
	$fields = parent::getCMSFields();

	$fields->addFieldToTab('Root.Content.Main', new TextField('MyField'));

	return $fields;
}

Where abouts did you get this code example from?


   function getCMSFields($cms) {
$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo'));
   return $fields;
   } 

This is a deprecated way of implementing getCMSFields().

Sean

Avatar
bones

Community Member, 110 Posts

27 September 2008 at 2:35am

Thanks guys.

I noticed that I didn't have the same problem with one of my other sites, and released that the problematic one was still using Silverstipe 2.2.1. I upgraded it, and now it works :)