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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

DOM and Uploadify image not attaching


Go to End


25 Posts   12444 Views

Avatar
aarono

Community Member, 34 Posts

24 February 2011 at 10:28am

Edited: 24/02/2011 10:33am

Hi UncleCheese,

That doest seemed to have helped unfortunately. This is a truly confusing problem.

Where is the refresh function so I can try debug inside there? I have looked inside FileUploadField and MultipleFileUploadField as both have a refresh() but if I try to print something to the browser, it doesnt show?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

24 February 2011 at 2:35pm

Look at line 42 or uploadify_init.js. It runs an ajax call to /YourFormField/refresh/:

$.ajax({
url: $e.metadata().refreshlink,
data: {'FileIDs' : ids.join(",")},
async: false,
dataType: "json",
success: function(data) {
$preview.html(data.html);
}
});

Make sure that's running!

Avatar
UncleCheese

Forum Moderator, 4102 Posts

24 February 2011 at 4:47pm

FYI, last time I saw this, the success function wasn't firing, despite the 200 response code. I eventually figured out that it had something to do with the content negotiator. It was bizarre.

But to test it, you can put an error handler in..

error : function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);

}

Avatar
aarono

Community Member, 34 Posts

25 February 2011 at 9:12am

Edited: 25/02/2011 9:27am

Hmm, I put the error handler in, but it doesnt throw anything. Where exactly should I put it? I think I have it in the wrong place...

I put this in the ajax call:

success: function(data) {
    alert(data);
    $preview.html(data.html);
}

and data comes back as null... So it is definitely running the function, but it isn't responding with the files?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

25 February 2011 at 9:51am

OK, that's actually a good thing because it probably means you can debug within PHP.

Look at UploadifyField::refresh(). There may be different refresh() functions for each descendant of UploadifyField, so make sure you check those first. I believe FileUploadField and MultipleFileUploadField, for instance, have their own refresh() handlers.

Find the right refresh() function and just start adding echo statements in the function, leaving your alert(data) statement in there. (console.log() is probably a better option for you, since it will show the contents of the returned object).

Start by putting an echo statement at the first line of the function and work your way down until you figure out why the return is coming back null, and let me know the results!

Avatar
aarono

Community Member, 34 Posts

25 February 2011 at 10:27am

Edited: 25/02/2011 10:31am

Ok making progress here. I found the correct refresh function - its MultipleFileUploadField::refresh(). I put an echo right at the very start of the function, but i was still getting null returned. So I copied the URL from the request into the browser and still got null. See here:
http://rocna.com/admin/EditForm/field/MediaImages/UploadifyForm/field/UploadedFiles/refresh?SecurityID=3751a3c35bcec9609407f090f86d285e97146dcc&ctf[MediaImages][start]=0&ctf[MediaImages][per_page]=10&ctf[MediaImages][showall]=0&ctf[MediaImages][sort]=SortOrder&ctf[MediaImages][sort_dir]=&ctf[MediaImages][search]=&ctf[MediaImages][filter]=&ctf[MediaImages][view]=grid&ctf[MediaImages][imagesize]=100&FileIDs=198

However, if I remove all the request data and just browse directly the function, like so:
http://rocna.com/admin/EditForm/field/MediaImages/UploadifyForm/field/UploadedFiles/refresh

I get a response along these lines (you can see my echo 'hello' at the start)

hello{"html":"
Attached files<\/div>\n
\n\t\n\t
\n\t\t\n\t\t\tNo files attached\n\t\t\n\t<\/div>\n\t\n<\/div>\n\n
\n\t\n<\/div>","success":"Added files successfully."}

Avatar
aarono

Community Member, 34 Posts

25 February 2011 at 10:32am

Edited: 25/02/2011 10:43am

Interesting.... now the url works, even with everything there...

http://rocna.com/admin/EditForm/field/MediaImages/UploadifyForm/field/UploadedFiles/refresh?SecurityID=3751a3c35bcec9609407f090f86d285e97146dcc&ctf[MediaImages][start]=0&ctf[MediaImages][per_page]=10&ctf[MediaImages][showall]=0&ctf[MediaImages][sort]=SortOrder&ctf[MediaImages][sort_dir]=&ctf[MediaImages][search]=&ctf[MediaImages][filter]=&ctf[MediaImages][view]=grid&ctf[MediaImages][imagesize]=100&FileIDs=198

But I havent changed anything since, so its intermittent??

UPDATE: Ok so I see a relation to what is causing the problem. This url works:
http://rocna.com/admin/EditForm/field/MediaImages/UploadifyForm/field/UploadedFiles/refresh?FileIDs=198
This one doesnt:
http://rocna.com/admin/EditForm/field/MediaImages/UploadifyForm/field/UploadedFiles/refresh?FileIDs=199

The file ID 198 DOESNT exits in the File table in the database, but 199 does... However, I cant see why that would cause my echo to not be returned, when its right at the start of the function:

public function refresh() {
		print_r('hello');
		ContentNegotiator::disable();
		$count = 0;
		$before = is_array($this->Value()) ? sizeof($this->Value()) : 0;
		if(isset($_REQUEST['FileIDs'])) {
			$ids = explode(",",$_REQUEST['FileIDs']);
			if(is_array($ids)) {
				$this->setValue($ids);
				$count = sizeof($ids) - $before;
			}
		}	
		return Convert::array2json(array(
			'html' => $this->renderWith('AttachedFiles'),
			'success' => sprintf(_t('Uploadify.SUCCESSFULADDMULTI','Added files successfully.'), $count)
		));
	}

Avatar
aarono

Community Member, 34 Posts

1 March 2011 at 3:57pm

Still stuck on this.... Any ideas UC?