PDA

View Full Version : [Solved]Form submit problem with zend framework



brunoflmg
16 Jul 2010, 11:23 AM
Hello!

My name is Bruno and I from Brazil. This is my first post and I hope I can publish help to another users soomsly.

Okay let's get started...

I have an simple extjs form and my problem is when I click 'Access' button the destiny Action of my authController not have values in $_POST array global. :-/:-/:-/

Debuguing post in Firebug:
21490

Server-side debugg:
21491

Okay where is the problem location?

Is in my EXTJS code? Or in Zend Framework reception?

I rebuild the same form without zend framework, just pure php. And with this way the thing works! :((

Link of the simple project without zend: http://dl.dropbox.com/u/3286508/testelogin.zip

Some body help me!!!

17 Jul 2010, 8:02 AM
Bruno,

using the form's submit method will automatically POST, GET, PUT or DELETE the values from the form.

I don't get why you're using Ext.get('component_name').getValue() (which is wrong) to post the values manually via the params object.

brunoflmg
18 Jul 2010, 6:13 AM
Jesus Garcia that cool talking to you.
I'm your fan and I follow all your screencasts, blog posts, tweets, ...

As for my question I relate my code and removed redundancies. However the problem still continues. At least now I know that the zend framework is concerned, not only found the solution yet.

I will continue assembling the puzzle in order to find a solution to this annoying problem!

Below is my form code updated



Ext.onReady(function(){

Ext.QuickTips.init();

var msg = function(title, msg) {
Ext.Msg.show({
title : title,
msg : msg,
minWidth: 200,
modal : true,
icon : Ext.Msg.INFO,
buttons : Ext.Msg.OK
});
};

var loginForm = new Ext.form.FormPanel({
xtype : 'form',
formId : 'form_login',
bodyStyle : 'padding:8px;',
labelAlign : 'top',
baseCls : 'x-plain',
items:[{
xtype : 'container',
layout : 'column',
defaults:{
xtype: 'container'
},
items:[{
columnWidth: '70px',
items:[{
baseCls : 'x-plain',
html : '<img src="'+ App.baseURL +'images/auth/security.png" border="0" style="margin:10px 8px 0 0"></img>'
}]
},
{
columnWidth: .7,
layout: 'form',
items:[{
xtype : 'textfield',
fieldLabel : 'Login',
name : 'user_login',
id : 'user_login',
allowBlank : false,
blankText : 'Digite seu login',
msgTarget : 'side',
anchor : '90%'
},
{
xtype : 'textfield',
fieldLabel : 'Senha',
name : 'user_password',
id : 'user_password',
inputType : 'password',
allowBlank : false,
blankText : 'Digite sua senha',
msgTarget : 'side',
anchor : '90%'
}]
}]
}]
});

var loginWindow = new Ext.Window({
title : 'Acesso restrito',
layout : 'fit',
iconCls : 'ico-cadeado',
height : 170,
width : 300,
scope : this,
closable : false,
resizable : false,
draggable : false,
items:
[loginForm],
buttons: [{
text : '<b>Entrar</b>',
iconCls : 'ico-app-go',
handler : function()
{
if( loginForm.getForm().isValid() )
{
loginForm.getForm().submit({
url : App.baseURL + 'auth/login',
method : 'POST',
waitTitle : 'Efetuando login',
waitMsg : 'Processando, aguarde...',
success: function(form, action){
msg('Success', 'Bem vindo!');
},
failure: function (form, action){
msg('Error', 'Erro ao efetuar login!');
}
});
}
}
}]
});

loginWindow.show();
});

brunoflmg
20 Jul 2010, 8:53 AM
Well I have already identified the cause of the problem. As the image below shows the form being submitted does not contain the fields user_login and user_password inside of "<form>..." markup.

See: http://www.brunowebdev.com.br/repo/form.JPG

That way the post received by the zend (PHP) is empty.

21538

My updated ext code:



// define o namespace
Ext.ns('App');

// path to the blank image should point to a valid location on your server
Ext.BLANK_IMAGE_URL = App.baseURL + '/scripts/ext-3.2.1/resources/images/default/s.gif';

Ext.onReady(function(){

Ext.QuickTips.init();

var msg = function(title, msg) {
Ext.Msg.show({
title : title,
msg : msg,
minWidth: 200,
modal : true,
icon : Ext.Msg.INFO,
buttons : Ext.Msg.OK
});
};

var loginForm = new Ext.form.FormPanel({
xtype : 'form',
formId : 'form_login',
id : 'form_login',
bodyStyle : 'padding:8px;',
labelAlign : 'top',
baseCls : 'x-plain',
items:[{
xtype : 'container',
layout : 'column',
defaults:{
xtype: 'container'
},
items:[{
columnWidth: '70px',
items:[{
baseCls : 'x-plain',
html : '<img src="'+ App.baseURL +'images/auth/security.png" border="0" style="margin:10px 8px 0 0"></img>'
}]
},
{
columnWidth: .7,
layout: 'form',
items:[{
xtype : 'textfield',
fieldLabel : 'Login',
name : 'user_login',
id : 'user_login',
allowBlank : false,
blankText : 'Digite seu login',
msgTarget : 'side',
anchor : '90%'
},
{
xtype : 'textfield',
fieldLabel : 'Senha',
name : 'user_password',
id : 'user_password',
inputType : 'password',
allowBlank : false,
blankText : 'Digite sua senha',
msgTarget : 'side',
anchor : '90%'
}]
}]
}]
});

var onSuccessOrFail = function(form, action) {
var result = action.result;
if (result.success) {
Ext.MessageBox.alert('Success',action.result.msg);
}
else {
Ext.MessageBox.alert('Failure',action.result.msg);
}
}

var loginWindow = new Ext.Window({
title : 'Acesso restrito',
layout : 'fit',
iconCls : 'ico-cadeado',
height : 170,
width : 300,
scope : this,
closable : false,
resizable : false,
draggable : false,
items:
[loginForm],
buttons: [{
text : '<b>Entrar</b>',
iconCls : 'ico-app-go',
handler : function()
{
if( loginForm.getForm().isValid() )
{
loginForm.getForm().submit({
url : 'auth',
waitTitle : 'Efetuando login',
waitMsg : 'Processando, aguarde...',
success: function(form, action){
var result = action.result;
if (result.success) {
msg('Sucesso:',action.result.msg);
}
else {
msg('Erro:',action.result.msg);
}
},
failure: function (form, action){
switch (action.failureType) {
case Ext.form.Action.CLIENT_INVALID:
Ext.Msg.alert('Erro', 'Form fields may not be submitted with invalid values');
break;
case Ext.form.Action.CONNECT_FAILURE:
Ext.Msg.alert('Erro', 'Ajax communication failed');
break;
case Ext.form.Action.SERVER_INVALID:
Ext.Msg.alert('Erro', action.result.msg);
}
}
});
}
}
}]
});

loginWindow.show();
});

brunoflmg
20 Jul 2010, 8:57 AM
Well I have already identified the cause of the problem. As the image below shows the form being submitted does not contain the fields user_login and user_password inside of "<form> ..." markup.

See the image in: http://www.brunowebdev.com.br/repo/form.JPG

That way the post received by the zend (php) is empty:

21539

brunoflmg
20 Jul 2010, 11:14 AM
I find the error... \o/
It's located in my ext form login script caused by this bold line below: (id: 'user_login',)



items:[{
xtype : 'textfield',
fieldLabel : 'Login',
name : 'user_login',
id : 'user_login',
allowBlank : false,
blankText : 'Digite seu login',
msgTarget : 'side',
anchor : '90%'
},
So... when I remove it the things works!

F__k! I lost mutch time because this issue!!!

20 Jul 2010, 11:17 AM
I don't see how the ID would be the issue, but glad you fixed it :)