Jump to:

10931 Posts in 2614 Topics by 1810 members

All other Modules

SilverStripe Forums » All other Modules » SWFUpload Issue

Discuss all other Modules here.

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

Page: 1 2 3 4
Go to End
Author Topic: 2582 Views
  • UncleCheese
    Avatar
    4085 Posts

    Re: SWFUpload Issue Link to this post

    You don't need a handleswfupload() function. It should fall back on SWFUploadControls by default.

    The way SWFUpload is configured is built totally wrong. It bootstraps all the javascript on construct instead of on FieldHolder(), which makes configuring it a pain. Just make sure you do all your SWFUploadConfig assignments before the field is constructed. Lame, I know.

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: SWFUpload Issue Link to this post

    Yeah I figured that, but it's still not working correctly. Here's my form constructor:

    class MessageForm extends Form
    {
    function __construct($controller, $name, $id = 0)
    {
    SWFUploadConfig::addFileTypes(array(
    'pdf', 'doc', 'jpg', 'png'
    ));

    SWFUploadControls::$file_class = "MessageFile";
    SWFUploadConfig::set_default_upload_dir("ProjectUploads");
    SWFUploadConfig::$debug = "true";

    $fields = singleton('Message')->getFrontEndFields();

    $fields->push(new HiddenField('ProjectId', 'ProjectId', $id));
    $fields->push(new SWFUploadField(
    $name,
    'Files',
    'Upload Files',
    array(
    'file_upload_limit' => '1',
    )
    ));

    $validators = new RequiredFields('Body');

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

    parent::__construct($controller, $name, $fields, $actions, $validators);
    }
    }

    All the configs are before the Field is pushed to the $fields collection, but it still no worky =(

  • UncleCheese
    Avatar
    4085 Posts

    Re: SWFUpload Issue Link to this post

    Which part doesn't work, exactly? The default upload dir? That needs to be in your _config.php, because it's not a SWFUpload setting. Make sure you've gotten rid of your handleswupload() function, too, cause that will override the functionality you're looking for.

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: SWFUpload Issue Link to this post

    Ok, now I'm totally confused. Nothing works at all. I've gone back to the beginning and started again.

    I have SWFUpload out of the box, latest version.

    Here's my form constructor:

    function __construct($controller, $name, $id = 0)
    {

    $fields = singleton('Message')->getFrontEndFields();

    $fields->push(new HiddenField('ProjectId', 'ProjectId', $id));
    $fields->push(new SWFUploadField($this, 'MessageFile', 'Upload Message Files'));

    $validators = new RequiredFields('Body');

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

    parent::__construct($controller, $name, $fields, $actions, $validators);
    }

    This is not even saving a file. No file in the Uploads directory, no record in the database in the Files or MessageFiles tables.

    I've created a class called MessageFile that has nothing in it but

    class MessageFile extends File
    {
    static $has_one = array('Message' => 'Message');
    }

    So if I understand correctly, this should work, but it should just save a file to uploads and do nothing with it, since I'm not setting the $file_class or handing it in my form's submit() method, right? And if I want to save a message file to the Uploads directory, I should just change $file_class at the beginning of my form's __construct method?

    Sorry for all the confusion, I'm utterly vexed . . .

    Attached Files
  • UncleCheese
    Avatar
    4085 Posts

    Re: SWFUpload Issue Link to this post

    This doesn't look right:

    SWFUploadField($this

    The first argument of SWFUploadField is the name of the form, e.g. "UploadForm"

  • UncleCheese
    Avatar
    4085 Posts

    Re: SWFUpload Issue Link to this post

    Sorry, let me rephrase that.. the first argument is the name of the function that creates the form.

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: SWFUpload Issue Link to this post

    So if you're subclassing Form, and building the form in the __construct function of your subclass, would that be "__construct"?

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: SWFUpload Issue Link to this post

    Ah, nevermind, it's the name of the form, which I am passing to the constructor in the $name variable

    2582 Views
Page: 1 2 3 4
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.