PDA

View Full Version : FileUploadField: not submitting file?



hallikpapa
2 Dec 2009, 10:18 AM
here is a simple form with a combo box and a upload field.



items: [{
label : 'Application',
id : 'application-combo-id',
xtype : 'combo',
valueField : 'id',
displayField : 'name',
hiddenName : 'app-id',
triggerAction : 'all',
store: new Ext.data.JsonStore({
url: '../extjs.php?list=apps',
root: 'data',
fields: ['id', 'name']
})
},{
xtype : 'fileuploadfield',
id : 'form-file',
emptyText : 'Select training file',
fieldLabel : 'File',
name : 'filepath'
}]



But when I POST to the server, it only submits the app-id, no file name or reference to the file on my system. Using ext3.0.3. What am I missing?



if(form.getForm().isValid()){
form.getForm().submit({
url: 'extjs.php',
waitMsg: 'Uploading new training document...',
success: function(fp, o){ //if success
Ext.MessageBox.alert('Upload Success','Press OK to continue.');
},
failure: function(fp, o){ //if not success
Ext.MessageBox.alert('Warning','Failure uploading document.');
}
});
}

2 Dec 2009, 10:42 AM
You won't see the post because it's actually in an iframe. are you setting the form to fileUpload : true?

husniadil
2 Dec 2009, 11:55 AM
It seems that your form is submitted with : application/x-www-form-urlencoded

change it to : multipart/form-data for uploading files...

how?

put
fileUpload: true in your FormPanel, and Extjs will change the enctype automatically, and you should be able to upload your files.



var form = new Ext.FormPanel({
fileUpload: true,
width: 500,
frame: true,
title: 'File Upload Form',
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [{
label: 'Application',
id: 'application-combo-id',
xtype: 'combo',
valueField: 'id',
displayField: 'name',
hiddenName: 'app-id',
triggerAction: 'all',
store: new Ext.data.JsonStore({
url: '../extjs.php?list=apps',
root: 'data',
fields: ['id', 'name']
})
},
{
xtype: 'fileuploadfield',
id: 'form-file',
emptyText: 'Select training file',
fieldLabel: 'File',
name: 'filepath'
}]
buttons: [{
text: 'Save',
handler: function () {
if (form.getForm().isValid()) {
form.getForm().submit({
url: 'extjs.php',
waitMsg: 'Uploading new training document...',
success: function (fp, o) { //if success
Ext.MessageBox.alert('Upload Success', 'Press OK to continue.');
},
failure: function (fp, o) { //if not success
Ext.MessageBox.alert('Warning', 'Failure uploading document.');
}
});
}
}
},
{
text: 'Reset',
handler: function () {
form.getForm().reset();
}
}]
});

hallikpapa
2 Dec 2009, 4:05 PM
Yeah I found that a little bit after posting my question, but for some reason it didn't show up on the forum for like 30 minutes after posting, so I couldn't delete this thread.

I appreciate the response, it was exactly what I needed. Thanks!

husniadil
3 Dec 2009, 9:31 AM
No problem..

dilip.khichade
13 Apr 2010, 4:02 AM
Can anybody tell me how to upload a file using Ext 2.2.1