可能重复:
how to get the form values and insert that values in the db using sencha touch
我对sencha touch的新手。我想创建一个表单并在数据库中提交表单详细信息。为此,我编写以下代码。
Ext.define("Form.view.Main",{
extend: "Ext.form.Panel",
requires:['Ext.Button',
'Ext.Spacer',
'Ext.field.Password'
],
config: {
fullscreen: true,
id:'form',
items: [
{
xtype:'fieldset',
items:[
{
xtype: 'textfield',
name : 'name',
label: 'Name'
},
{
xtype: 'emailfield',
name : 'email',
label: 'Email',
placeHolder: 'Email address',
useClearIcon: true
},
{
xtype: 'passwordfield',
name : 'password',
label: 'Password',
allowBlank:'false'
}
]
},
{
centered:'true',
xtype:'button',
id:'submitBtn',
text:'Submit',
ui:'confirm',
width:100,
listeners: {
tap : function(thisTxt,eventObj){
var form = Ext.getCmp('form');
var values = thisTxt.getValues();
alert(values.name);
Ext.Ajax.request({
url:'http://localhost/sencha2011/form/insert.php',
params:values,
success : function(response){
var text = response.responseText;
Ext.Msg.alert('Success', text);
},
failure : function(response){
Ext.Msg.alert('Error','Error while submitting the form');
console.log(response.responseText);
}
});
}
}
}
]
}
});
当我尝试执行此应用程序时,执行(调试)成功。当我在浏览器中打开应用程序时,我在控制台窗口中出现“Uncaught TypeError:无法调用方法'getValues'未定义”的错误,并且表单只显示。当我点击提交按钮时没有任何反应。任何人都可以帮助解决这个问题。 提前谢谢......
答案 0 :(得分:0)
首先,您将表单的id
放在错误的位置,它应该放在items
config
config: {
fullscreen: true,
id: 'form'
items: [
...........
}
其次,您的查询错误,请更改此查询:
var form = Ext.getCmp(form);
到此:
var form = Ext.getCmp('form');
最后,由于getvalues
会返回一个包含表单中每个字段值的对象,因此如果您想要访问name
字段,请执行以下操作:
alert(values.name);
希望有所帮助:)
答案 1 :(得分:0)
而不是
var values = thisTxt.getValues();
尝试
var values = form.getValues();
或
var values = this.parent.getValues();
因为thisTxt
是button而不是表单,getValues()应该在表单面板上调用。