PDA

View Full Version : send formPanel values via ajax



titzu
18 Aug 2009, 6:09 AM
Hi,
I need to send all formPanel elements via ajax.

Thanks in advance,
Titzu

here is my code:



<script type="text/javascript">

Ext.onReady(function(){

var checkGroup = {
xtype: 'fieldset',
title: 'Set Default Questions - Step 1',
autoHeight: true,
layout: 'form',
collapsed: false,
collapsible: true,
items: [{
xtype: 'checkboxgroup',
itemCls: 'x-check-group-alt',
columns: 3,
vertical: true,
items: [
<?php foreach($this->form as $key=>$value): ?>
{boxLabel: '<?php echo $value["field"] ?>', name: 'ch' <?php if ($value["flag"]==1) echo ',checked: true'; ?>},
<?php endforeach; ?>
]
}]
};

var fp = new Ext.FormPanel({
header:false,
id: 'fp',
frame: true,
labelWidth: 110,
autoWidth: true,
bodyStyle: 'padding:0 10px 0;',
items: [
checkGroup
],
buttons: [{
text: 'Done - Go to Step 2',
disabled: false,
listeners: {
click: function(button, event) {
//var formDom = fp.getForm().getEl('ch[]').getValue();
var formDom=Ext.get('ch[]').dom.value;

Ext.Ajax.request({
url: '<?php echo Zend_Registry::get('config1')->site->url; ?>formbuilder/admin/step1',
success : function(result) {
var json = Ext.decode(result.responseText);
if (json.success === true) {
alert('cacat');
}
else {
Ext.MessageBox.alert('Error!', 'The move request failed.');
}
},
failure : function() {
Ext.MessageBox.alert('Error!', 'The move request failed.');
},
params: { foo: 'bar', form: formDom }
});

}
}
},{
text: 'Reset',
handler: function(){
fp.getForm().reset();
}
}]
});

Ext.getCmp('step1').add(fp);
Ext.getCmp('step1').doLayout();
});


</script>

18 Aug 2009, 6:12 AM
send the elements or their values??

if so, why are you not using FormPanel.getForm().submit({}); ??

Also, please post your problem, not what you *want*.

titzu
18 Aug 2009, 6:16 AM
the elements value of course.
I dont want to use FormPanel.getForm().submit({}); because I dont want to refresh the page.

18 Aug 2009, 6:19 AM
by *default* it does not do a page refresh, uses XHR to send the data. have you *looked* at the API?

titzu
18 Aug 2009, 6:40 AM
I am incredibly stupid ...
Thanks for making me realize that :)

httpdotcom
18 Aug 2009, 7:58 AM
or you can add
,params: fp.getForm().getValues() to your Ajax call, but jgarcia's recommendation is still the preferred option.