Jump to:

1971 Posts in 1275 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » loadUploaded creates record with wrong ClassName?

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

Page: 1
Go to End
Author Topic: 1038 Views
  • _Vince
    Avatar
    Community Member
    156 Posts

    loadUploaded creates record with wrong ClassName? Link to this post

    I'm trying to create a form, on the front end, where users can upload a logo.

    I am using a SimpleImageField

    $fields = new FieldSet(
    .
    .
    .
    new SimpleImageField (
    $name = "LogoImageID",
    $title = "Upload a logo (2Mb maximum filesize)"
    )
    );
    .
    .
    .
    $form = new Form($this, 'ShowProfileForm', $fields, $actions, );
    return $form;
    }

    function btnSaveInfo($data, $form) {

    $file = new File();
    $file->loadUploaded($_FILES['LogoImageID']);

    And that WORKS, except that the Image is saved with a ClassName of "File" rather than "Image". So it doesn't display on the template or do anything useful.

    I can't find any documentation on how to set the ClassName.

    When I try updating the ClassName with a DataObject::get_by_id, I get a message about backlinktracking not being supported. And anyway, it's a total kludge of a solution.

    At the moment, I can get it to work by simply updating the record with a DB:query (even more of a kludge), but there's got to be a better solution.

    I can't be the only guy that's noticed this problem, so I am sure I'm doing something wrong.

    Any suggestions?

  • Juanitou
    Avatar
    Community Member
    322 Posts

    Re: loadUploaded creates record with wrong ClassName? Link to this post

    Hi!

    Can’t you simply use $file = new Image(); ?

    Hope it helps,
    Juan

  • _Vince
    Avatar
    Community Member
    156 Posts

    Re: loadUploaded creates record with wrong ClassName? Link to this post

    Oh!

    Yes, that's definitely worth a try. Thanks for the suggestion!

    Later:

    Yup. It works, thanks for that. I guess I should read and adapt the documentation rather than take it literally.

    Cheers!

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