Posting form data and ajax updates
I have the following as a form panel, which is a simple keyword search
var keyword_search = new Ext.FormPanel({
renderTo: 'contentDiv',
labelWidth:160,
frame:false,
autoWidth:true,
bodyStyle:'padding:20px 20px 20px 20px',
defaults: {width: 400},
defaultType:'textfield',
method:'POST',
enctype : 'multipart/form-data',
items: [{
fieldLabel: 'Keyword',
name: 'keyword',
value: ''
},
new Ext.form.Hidden({
name: 'search',
value: 'keyword'
}),
],
buttons: [{
text: 'Save',
handler:function(){
profile.getForm().submit({
method:'POST',
enctype : 'multipart/form-data',
waitTitle:'Connecting',
waitMsg:'Searching catalogue...',
url:'content.php?action=course_catalogue',
success:function(){
Ext.Msg.alert('Ok', 'Profile update successful!');
},
failure:function(form, action){
if(action.failureType == 'server'){
obj = Ext.util.JSON.decode(action.response.responseText) ;
Ext.Msg.alert('Profile update failed!', obj.errors.reason);
}else{
Ext.Msg.alert('Warning!', 'Authentication server is unreachable !');
}
//simple.getForm().reset();
}
});
}
}]
});
How would I go about changing this so that instead of it returning the message alert on success, it still posts the form variables to the url specified in the save button, but then returns the resulting output to the contentDiv div using the extjs ajax updater functionality.
Thanks in advance
success:function(form, action){
// Ext.Msg.alert('Ok', 'Successful!');
Ext.fly('server-result').update(action.result.msg);
/*
bascially (I'm guessing) what I need to do is get the return data
from form_submit_test.php here and then update contentDiv
to display it ?
*/
},
And server:
if ($return){
echo '{success:true,msg:"A message delivered from server"}';
}else {
echo '{success: false,
errors: {
reason: "An error occured with the form submission"
}}';
}
Add
success:function(form, action){
// Ext.Msg.alert('Ok', 'Successful!');
Ext.fly('server-result').update(action.result.msg);
/*
bascially (I'm guessing) what I need to do is get the return data
from form_submit_test.php here and then update contentDiv
to display it ?
*/
},
And server:
if ($return){
echo '{success:true,msg:"A message delivered from server"}';
}else {
echo '{success: false,
errors: {
reason: "An error occured with the form submission"
}}';
}
Add
Added them, now I don't get an error, but the div does not update. I tested the update function by replacing action.response.msg with a simple string, and that works, so its just getting the data to return from the post url. Will keep trying my side, let me know if you think of anything.
This has always been the fastest way to help as I can modify your code, see the results immediately and post the solution back very fast.
Will post shortly... thanks for the assistance thus far
To your original question: Could you please rephrase what is your desired behavior?
To get fastest response in the case you post some code, post it in the form that can be copied somewhere to the Ext tree and run locally.
You'll see I have added notes in the scripts as to where I am lost. Basically I need to be able to return data on the form success function to then display in the main div ('contentDiv').
Let me know if anything doesn't make sense.
Needed to code the success function like the error function
success:function(form, action){
obj = Ext.util.JSON.decode(action.response.responseText) ;
Ext.fly('server-result').update(obj.msg);
},
Works brilliantly, thanks mate.:D
Do you mind if I post other questions regarding other stuff in this thread, or should I start a new one...just so much to learn.
#If you have any other info about this subject , Please add it free.# |