Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Adding an image tab to a Contact Form

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

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

Page: 1
Go to End
Author Topic: 1479 Views
  • bones
    Avatar
    Community Member
    104 Posts

    Adding an image tab to a Contact Form Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Adding an image tab to a Contact Form Link to this post

    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!

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Adding an image tab to a Contact Form Link to this post

    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

  • bones
    Avatar
    Community Member
    104 Posts

    Re: Adding an image tab to a Contact Form Link to this post

    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

    1479 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.