Jump to:

5520 Posts in 1734 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » FileField in Tab

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

Page: 1
Go to End
Author Topic: 910 Views
  • Jarek
    Avatar
    Community Member
    30 Posts

    FileField in Tab Link to this post

    Hello,

    I'm creating new CMS compontent based on banner table. Baner has got image:

    static $has_one = array(
    'file' => 'File'
    );   

    so I've created getCMSFields method:

    public function getCMSFields() {

    $fields = new FieldSet(
    new TabSet("Root",
    new Tab('Dane podstawowe',

    new FileField( 'file', 'Baner', null, null, null, 'banery'),

    and in BannerAdmin.php I've created edit form method

    function getEditForm($id)
    {

    $actions = new FieldSet(
    new FormAction('doUpdateBanner', 'Save')
    );

    $form = new Form($this, "EditForm", $fields, $actions);


    return $form;
    }

    In cms form is created and has enctype multipart/form-data but when I submit firebug shows application/x-www-form-urlencoded; charset=utf-8 and $_FILES is empty. I don't know why enctype is changing.

    In firebug I've spotted that submit input is outside <form> tags. But in form.ss everything is inside <form>… When I've moved (using firebug) sumit field inside <form> everything is ok. So it looks like submit is in wrong place. How can I fix it?

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: FileField in Tab Link to this post

    Hi Jarek,

    Because the CMS is all Ajax based it doesn't handle file upload normally. You need to upload the file with an iframe. Fortunately there's a tool that does this for you. Use a FileIFrameField instead of a FileField and it should all be good.

    If your file is going to be an image, you can use ImageField instead of FileIFrameField, which operates similarly but has thumbnails.

    Thanks,
    Sam

  • Jarek
    Avatar
    Community Member
    30 Posts

    Re: FileField in Tab Link to this post

    Hi,

    where is code that submits form using ajax? It should be possible to set correct form enctype.

    I've tried to use IFrameField but I'me getting "I can't handle sub-URLs of a xxx object" error

    910 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.