in the following example when we click the button, all the form data (both the KEY-VALUE
) will be passed to the php file to be saved in the database. Grabbing the KEY-VALUE
is done by var form = this.up('form').getForm();
statement.
UPDATE 3
Ext.define ('Mycomp.model.MyClass',{
extend: 'Ext.data.Model',
fields:['textfieldone']
});
========================================================================
UPDATE 2
When a user clicks on a button, i display the View that has one textfield and a button (as shown in the following code). The user will enter some values and click on the button, and the value entered by the user in the text field should be saved in the DB (The Store
has the link to the path of the PHP code)
CONTROLLER
Ext.define('Mycomp.controller.MyClass',{
extend: 'Ext.app.Controller',
stores:['MyClass'],
models:['MyClass'],
views:['MyClassView'],
init: function(){
this.control({
'myclassview button[action=save]': {
click: this.myMethod
}
});
},
myMethod: function(button,record) {
var win = button.up('window'),
form = win.down('form'),
record = form.getForm().getRecord(),
values = form.getForm().getValues();
console.log (values);
console.log (record);
record.getRecord().set(values);
win.close();
this.this.getMyClassStore().sync();
}
});
VIEW
Ext.define('Mycomp.view.user.MyClassView', {
extend: 'Ext.window.Window',
alias: 'widget.myclassview',
initComponent: function() {
this.items = [
{
xtype: 'form',
items: [
{
xtype: 'textfield',
name : 'textfieldone',
fieldLabel: 'Contact Person Name'
}
]
}
];
this.buttons = [
{
text: 'Save',
name:'save',
action: 'save'
}
];
this.callParent(arguments);
}
});
STORE
Ext.define('Mycomp.store.Myclass',{
extend:'Ext.data.Store',
model:'App.model.Myclass',
proxy: {
actionMethods : {
create : 'POST'
},
type: 'ajax',
url : '/savetodb.php'
}
});
===============================================================================
UPDATE 1
.... this.buttons = [
{
text: 'Save',
action: 'save'
}, ...
STORE
Ext.define('Mycomp.store.Myclass',{
extend:'Ext.data.Store',
model:'App.model.Myclass',
proxy: {
actionMethods : {
create : 'POST'
},
type: 'ajax',
url : '/savetodb.php'
}
});
CONTAROLLER
this.control({
'mycalssform button[action=save]': {
click: this.myMethod
}
});
},
myMethod: function(button, record) {
var win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues();
console.log (record);
console.log (values );
record.set(values);
win.close();
this.this.getmyClassStore().sync();
FIREBUG OUT PUT >> It says RECORD IS UNDEFINED . Why is this ?
undefined
Object { textfileldone="hello", textfileldtwo="bever", more...}
record is undefined
[Break On This Error]
record.set(values);