PDA

View Full Version : Get php variable value (which is actualy taken from db) in extjs' textfield



maaz
8 Oct 2011, 9:36 AM
Hi Guys, I am making an app using ExtJS and PHP. As I am new in ExtJS . I have used simple HTML forms before
But now i want to put php variable value in textfield
my code is


Ext.require([
'Ext.form.*'
]);

Ext.onReady(function() {

var formPanel = Ext.create('Ext.form.Panel', {
frame: true,
url:'controller/addreadymade.php',
title: 'Form Fields',
width: 340,
bodyPadding: 5,

fieldDefaults: {
labelAlign: 'left',
labelWidth: 90,
anchor: '100%'
},

items: [{
xtype: 'displayfield',
name: 'serial',
fieldLabel: 'Serial Number',
value: '<span style="color:red;">system generated</span>' // require php variable value here from server. :s
},{
xtype: 'textfield',
name: 'item_num',
fieldLabel: 'Item Number'
}],
buttons: [{
text: 'Reset',
handler:function(){formPanel.getForm().reset() }
},{

text:'Add',
formBind: true,
// Function that fires when user clicks the button
handler:function(){
formPanel.getForm().submit({
method:'POST',
waitTitle:'Connecting',
waitMsg:'Sending data...',

success:function(form, action){
//do something
},
failure:function(form, action){
/do something
}
});
}

}]
});

formPanel.render('content');

});




please help me guys
Regards,
Maaz

mikhailt
10 Oct 2011, 1:18 AM
You either need to parse variabel as global to JavaScript before render a page
output in php something like this

print "<script type='text/javascript'>var MyJSVar = ". $MyPHPVar."</script>"

or run asynchronous request (AJAX) Ext.Ajax.request

nareh tank
10 Oct 2011, 5:10 AM
hi,
You have to use Ext.Ajax.request() method and get json response from php file .
and set response data as textbox value by using setValue() method .
that's it .

thanks