PDA

View Full Version : remember username and password when type the name is textbox



frank_ash
4 Aug 2009, 10:03 PM
hi,
how to remember username and password in loginpage when enter the username in textbox..

thanks is advance...

Condor
4 Aug 2009, 11:48 PM
Do you want to remember it in code using a Cookie? Have a look at the Ext.state.CookieProvider class...

Or do you want to use the browser autocomplete feature? In that case you input fields must already exist in the HTML, e.g.

<script type="text/javascript">
new Ext.Window({
el: 'login',
title: 'Welcome',
width: 260,
resizable: false,
closable: false,
layout: 'form',
defaultType: 'textfield',
bodyStyle: 'padding: 5px;',
defaults: {
anchor: '-20',
allowBlank: false
},
items: [{
id: 'username',
el: 'username',
fieldLabel: 'Username'
},{
id: 'password',
el: 'password',
fieldLabel: 'Password'
}],
defaultButton: 'username',
buttonAlign: 'center',
buttons: [{
text: 'Login',
handler: function(){
Ext.getDom('submit').click();
}
}]
}).show();
</script>
<body>
<form id="login" method="post" action="j_security_check" class="x-hidden">
<input type="text" id="username" name="j_username" />
<input type="password" id="password" name="j_password" />
<input type="submit" id="submit" value="Login" class="x-hidden" />
</form>
</body>

ggranum
2 Jan 2010, 6:24 PM
"Or do you want to use the browser autocomplete feature? In that case you input fields must already exist in the HTML, e.g."

This nifty example or at least the information in general would be right at home in the BasicForm or FormPanel docs :~)

borg
25 Jan 2010, 7:20 AM
what if in my button handler I want to do this ajax type of submit rather than a normal post, how would i do it? Ext.getCmp('login').getForm() doesn't work



Ext.getCmp('login').getForm().submit({
url: scriptlocation,
waitMsg: 'Submitting...',
success: function(form, action) {
Ext.Msg.wait('Redirecting...');
window.location = 'test.htm';
},
failure: function(form, action) {
var msg = '';
if (action.failureType == Ext.form.Action.CLIENT_INVALID) {
msg = 'Invalid password.';
}
else if (action.failureType == Ext.form.Action.CONNECT_FAILURE) {
msg = 'Connection failure.';
}
else if (action.failureType == Ext.form.Action.LOAD_FAILURE) {
msg = 'Load failure.';
}
else if (action.failureType == Ext.form.Action.SERVER_INVALID) {
var jsonData = Ext.util.JSON.decode(action.response.responseText);
if (jsonData['error']) {
msg = jsonData['error'];
}
}

Ext.Msg.show({
title: 'Error',
msg: msg,
modal: true,
closable: false,
icon: Ext.Msg.ERROR,
buttons: Ext.Msg.OK,
fn: function (btn){
Ext.get('password').focus();
}
});
}
});

Condor
25 Jan 2010, 7:30 AM
For the autocomplete to work you must do a standard submit, otherwise the entered username and password aren't stored.

The only thing you could try is:

Ext.get('login').on('submit', function(){
Ext.getCmp('login').getForm().submit({
...
});
}, null, {stopEvent: true});
I'm not sure if this also stores the username and password...

borg
25 Jan 2010, 7:55 AM
tried that code, just did a standard submit. OK well if I can't do an ajax submit I don't want to use the save form field data anyway. thanks for the info

mitchellsimoens
25 Jan 2010, 8:01 AM
this works on my applications:


var formOnSuccessorFail = function(form, action) {
if (action.result.success) {
//do whatever you want
} else {
Ext.MessageBox.alert("Error", action.result.msg);
}
}

var formSubmitHandler = function() {
var form = Ext.getCmp("myForm");
form.getForm().submit({
url: "functions.php",
params: {
one: "something"
},
success: formOnSuccessorFail,
failure: formOnSuccessorFail
});
}

On my button I have it call formSubmitHandler()

sirioz10
7 Apr 2011, 5:33 AM
this works on my applications:


var formOnSuccessorFail = function(form, action) {
if (action.result.success) {
//do whatever you want
} else {
Ext.MessageBox.alert("Error", action.result.msg);
}
}

var formSubmitHandler = function() {
var form = Ext.getCmp("myForm");
form.getForm().submit({
url: "functions.php",
params: {
one: "something"
},
success: formOnSuccessorFail,
failure: formOnSuccessorFail
});
}On my button I have it call formSubmitHandler()

Can you explain me your code?

var form = Ext.getCmp("myForm");

What is myForm?

fay
7 Apr 2011, 6:08 AM
From the Ext.getCmp docs (http://dev.sencha.com/deploy/dev/docs/?class=Ext&member=getCmp):



This is shorthand reference to Ext.ComponentMgr.get (http://dev.sencha.com/deploy/dev/docs/output/Ext.ComponentMgr.html#Ext.ComponentMgr-get). Looks up an existing Component (http://dev.sencha.com/deploy/dev/docs/output/Ext.Component.html) by id (http://dev.sencha.com/deploy/dev/docs/output/Ext.Component.html#Ext.Component-id).


So "myForm" is the value of the 'id' config param specified for that form.

akrherz
28 May 2011, 6:42 PM
Hi,

Would anybody kindly post a working example of this? I can't seem to figure out a combination that works among all browsers and OS. Currently, I have an extra button on the login window whose handler is


Ext.getDom('submit').click();

where there is a submit button with id of submit. This then goes to a simple php page that redirects back to the application. This catches most users, but not all.

thanks,
daryl

PTG
12 Jun 2011, 1:34 AM
This doesn't work anymore with ExtJS 4 :(

gauravbdubey
4 Nov 2011, 1:58 AM
Hello ,
I want remember username and password is it possible in sencha toch