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.

All other Modules /

Discuss all other Modules here.

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

SWFUpload Issue


Go to End


25 Posts   4313 Views

Avatar
UncleCheese

Forum Moderator, 4102 Posts

16 March 2010 at 5:22am

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.

Avatar
tbarho

Community Member, 41 Posts

16 March 2010 at 7:19am

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 =(

Avatar
UncleCheese

Forum Moderator, 4102 Posts

16 March 2010 at 7:48am

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.

Avatar
tbarho

Community Member, 41 Posts

16 March 2010 at 4:27pm

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
Avatar
UncleCheese

Forum Moderator, 4102 Posts

16 March 2010 at 4:51pm

This doesn't look right:

SWFUploadField($this

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

16 March 2010 at 4:53pm

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

Avatar
tbarho

Community Member, 41 Posts

17 March 2010 at 12:12pm

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

Avatar
tbarho

Community Member, 41 Posts

17 March 2010 at 12:16pm

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