29/09/2011 8:03pm

Javascript | Problem - Uploadify + jQuery Form plugin


Form class:

function __construct($controller, $name) {
$fields = new FieldSet(
$images = new MultipleFileUploadField('Images', _t('UploadForm.IMAGES', 'Images'))
);
$actions = new FieldSet(
new FormAction('doupload', _t('UploadForm.UPLOAD', "Upload"))
);
$images->setFileTypes(array(
'png',
'gif',
'bmp',
'jpg',
'jpeg'
));
//$images->uploadOnSubmit();
parent::__construct($controller, $name, $fields, $actions);
}
public function doupload($data, $form) {
$memberID = Member::currentUserID();
if(isset($data['Images']) && is_array($data['Images'])) {
foreach($data['Images'] as $id) {
if($file = DataObject::get_by_id("File", (int) $id)) {
$bookImage = new BookImage();
$bookImage->ImageID = $file->ID;
$bookImage->MemberID = $memberID;
$bookImage->write();
}
}
}
$response['success'] = True;
$response['message'] = _t('CartController.UPLOADSUCCESS', 'Your upload was successful!');
}


Javascript:
$('#UploadForm_UploadForm').ajaxForm({
dataType: 'json',
success: function(data) {
var url = window.location.pathname + '/show_mygallery';
$('#ImageList').load(url, function() {
// Clear uploadify form
$('#UploadForm_UploadForm .inputs input').remove();
$('#UploadForm_UploadForm .upload_previews li').remove();
});
}
});

uploadify_init.js:
onAllComplete : function(event) {
$e = $(event.currentTarget);
$e.data('active',false);
$e.parents('form').find(':submit').attr('disabled',false).removeClass('disabled');
$container = $e.parents('.UploadifyField:first');
$('.preview',$container).show();
if($e.metadata().upload_on_submit) {
$e.parents('form').submit();
}

},


Post Comment