Code:
Ext.ns('Example');
Example.Form = Ext.extend(Ext.form.FormPanel, {
// configurables
border:false
,frame:true
,labelWidth:80
,bodyStyle:'padding:20px 20px 0'
,url:script_path + 'login.php'
,initComponent:function()
{
// configure ourselves
Ext.apply(this, {
defaultType:'textfield'
,defaults:{anchor:'-24'}
,monitorValid:true
// ,buttonAlign:'right'
,items:
[{
name:'username'
,fieldLabel:'User Name'
,allowBlank:false
,id:'user_name'
,vtype:'alphanum'
},{
name:'password'
,fieldLabel:'Password'
,inputType: 'password'
,allowBlank:false
,vtype:'alphanum'
}]
,buttons:[{
text:'Log In'
,scope:this
,formBind:true
,handler:this.submit
}]
,keys:[{
key:[10,13] // enter
,scope:this
,stopEvent:true
,fn:this.submit
}]
}); // eo apply
// call parent
Example.Form.superclass.initComponent.apply(this, arguments);
} // eo function initComponent
/**
* Form onRender override
*/
,onRender:function()
{
// call parent
Example.Form.superclass.onRender.apply(this, arguments);
// set wait message target
this.getForm().waitMsgTarget = this.getEl();
Ext.getCmp('user_name').focus('', 10);
} // eo function onRender
/**
* Load button click handler
*/
,onLoadClick:function()
{
this.load({
url:this.url
,waitMsg:'Loading...'
,params:{mode:'load'}
});
// any additional load click processing here
} // eo function onLoadClick
/**
* Submits the form. Called after Submit buttons is clicked
* @private
*/
,submit:function()
{
// form variable
var basicForm = this.getForm();
// If form validated then only allow to submit
if(basicForm.isValid()){
this.getForm().submit({
url:this.url
,scope:this
,method:'post'
,params:{mode:'checkUser'}
,success:this.onSuccess
,failure:function(form, action){
Ext.Msg.show({
title:'Invalid Login'
,msg:'Invalid User Name or Password'
,modal:true
,icon:Ext.Msg.ERROR
,buttons:Ext.Msg.OK
});
this.getForm().reset();
Ext.getCmp('user_name').focus('', 10);
}
,waitMsg:'Loading Please wait...'
});
}
} // eo function submit
/**
* Success handler
* @param {Ext.form.BasicForm} form
* @param {Ext.form.Action} action
* @private
*/
,onSuccess:function(form, action)
{
window.location.href = "index.php";
} // eo function onSuccess
/**
* Shows Message Box with error
* @param {String} msg Message to show
* @param {String} title Optional. Title for message box (defaults to Error)
* @private
*/
,showError:function(msg, title)
{
title = title || 'Error';
Ext.Msg.show({
title:title
,msg:msg
,modal:true
,icon:Ext.Msg.ERROR
,buttons:Ext.Msg.OK
});
} // eo function showError
}); // eo extend
// register xtype
Ext.reg('exampleform', Example.Form);
Ext.BLANK_IMAGE_URL = ext_path + 'resources/images/default/s.gif';
// application main entry point
Ext.onReady(function()
{
Ext.QuickTips.init();
// invalid markers to sides
Ext.form.Field.prototype.msgTarget = 'side';
var win = new Ext.Window
({
id:'formloadsubmit-win'
,title:Ext.fly('page-title').dom.innerHTML
,layout:'fit'
,width:350
,height:170
,closable:false
,border:false
,draggable : false
,resizable :false
,monitorValid:true
,items:{id:'formloadsubmit-form', xtype:'exampleform'}
});
win.show();
}); // eo function onReady
// eof
Many thanks