PDA

View Full Version : error when form is submitting



Masat0
11 Jan 2013, 4:11 AM
I have form which submitted successfully, but I added filefield and got error:
Uncaught exception: TypeError: Cannot convert 'result' to object
Error thrown at line 221, column 8 in <anonymous function: onSuccess>(response) in /extjs/src/form/action/Submit.js?_dc=1357906359290:
if (result !== true && !result.success) and object
msg "You're trying to decode an invalid JSON String: "
sourceClass "Ext.JSON"
sourceMethod "decode"
But form is sending.


Ext.define('App.view.admin.indicator.Edit' ,{
extend: 'Ext.form.Panel',
alias : 'widget.form_indicator_edit',

padding: '0 15 0 5',
autoScroll: true,
style: 'background-color: #fff;',


defaults: {
layout: {
type: 'hbox',
pack: 'start',
align: 'stretch'
},
padding: '15 0 0 0',
},

items: [
{
xtype: 'container',
items: [
{
xtype: 'label',
html: '?????????? ????? <span style="color: rgb(255, 0, 0); padding-left: 2px;">*</span>',
width: 150,
},
{
xtype: 'textfield',
name : 'index_number',
flex: 1,
allowBlank: false,
padding: '0 10 0 10',
},
],
},
{
xtype: 'container',
items: [
{
xtype: 'label',
html: '????',
width: 150,
},
{
xtype: 'filefield',
name : 'file_instruction',
flex: 1,
padding: '0 10 0 10',
buttonText: '???????? ????',
vtype: 'fileInstruction',
},
],
},


{
xtype: 'container',
items: [
{
xtype: 'button',
text: '?????????',
action: 'save'
},
],
},
]
});

in controller I use form.submit().

Which options should I set in method submit that I can submit the form without this error?

friend
11 Jan 2013, 5:14 AM
I don't see a url property in your form configuration. Are you specifying the url in the body of the form.submit() method?

The error you're reporting sounds as if the server-side response is not in a JSON format or is returning something unexpected.

Masat0
11 Jan 2013, 5:38 AM
Yes, I specify url in the body form.submit.

I check server-side


echo json_encode(array("success" => true, "message" => 'test' ));
exit; When I use form without filefield there is not error. When I add filefield, I get error and get reply from server.

friend
11 Jan 2013, 6:25 AM
Is your server-side code doing multipart/form-data handling?

Masat0
11 Jan 2013, 1:29 PM
I try test.
app.js

Ext.application({
requires: ['Ext.container.Viewport'],
name: 'AM',
appFolder: 'app',


controllers: [
'Test'
],

launch: function() {
Ext.create('Ext.container.Viewport', {
layout: 'fit',
items: [
{
xtype: 'testform',
}
]
});
}
});



view TestForm.js

Ext.define('AM.view.TestForm' ,{
extend: 'Ext.form.Panel',
alias : 'widget.testform',

padding: '0 15 0 5',
autoScroll: true,
style: 'background-color: #fff;',
id: 'form_id',




defaults: {
layout: {
type: 'hbox',
pack: 'start',
align: 'stretch'
},
padding: '15 0 0 0',
},

items: [
{
xtype: 'container',
items: [
{
xtype: 'label',
html: 'test <span style="color: rgb(255, 0, 0); padding-left: 2px;">*</span>',
width: 150,
},
{
xtype: 'textfield',
name : 'index_number',
flex: 1,
allowBlank: false,
padding: '0 10 0 10',
},
],
},
{
xtype: 'container',
items: [
{
xtype: 'label',
html: 'file',
width: 150,
},
{
xtype: 'filefield',
name : 'file_instruction',
flex: 1,
padding: '0 10 0 10',
buttonText: 'select file',
},
],
},
{
xtype: 'container',
items: [
{
xtype: 'button',
text: 'Save',
action: 'save'
},
],
},
]
});


controller Test.js

Ext.define('AM.controller.Test', {
extend: 'Ext.app.Controller',


views: [
'TestForm'
],

init: function() {
this.control({
'testform button[action=save]': {
click: this.testSendForm
},
});
},

testSendForm: function() {
var form = Ext.getCmp('form_id').getForm();




if(form.isValid()) {

form.submit({
waitMsg:'?????? ???????????...',
timeout: 30,
url: 'response.php',
success: function(form, action) {
console.log('success '+action.response.responseText);
},
failure: function(form,action){
console.log(action.response.responseText);
}
});
}
},
});


server-side response.php

<?php
echo json_encode(array("success" => true, "message" => 'test' ));
exit;
?>


When I comment filefield in view, I get
{"success":true,"message":"test"} in console. When I use filefield, I get
Uncaught exception: Ext.Error: You're trying to decode an invalid JSON String:
...
Ext.Error.raise({sourceClass:"Ext.JSON",sourceMethod:"decode",msg:"You're trying to decode an invalid JSON String: "+json})
and
{"success":true,"message":"test"} The form was sent and the reply was recieved inspite of this error. I don't have any ideas.

Masat0
13 Jan 2013, 10:17 AM
Ok. I ran example "File Upload Field" from sencha docs and I got same error. I inserted console.log in form/action/Submit.js and I got two output. The first is emty string, the second is that php echo send from server. Why when I use filefield in form then Submit.js is called twice?

I check that this error occurs in opera 12.01 on Linux. There is not error in FF and Chrome