PDA

View Full Version : Ext.lib.Ajax.formRequest method is hardcoded to POST



corey.gilmore
25 Apr 2007, 10:00 AM
In the latest SVN build all *-bridge Ext.lib.Ajax.formRequest functions are hardcoded to use POST as the method.
From yui-bridge.js


Ext.lib.Ajax = {
...
formRequest : function(form, uri, cb, data, isUpload, sslUri){
CN.setForm(form, isUpload, sslUri);
return CN.asyncRequest('POST', uri, cb, data);
},

corey.gilmore
25 Apr 2007, 10:15 AM
A quick fix for YUI for anyone who needs it:


formRequest : function(form, uri, cb, data, isUpload, sslUri){
CN.setForm(form, isUpload, sslUri);
return CN.asyncRequest(form.method ? form.method.toUpperCase() : 'POST', uri, cb, data);
},


If you use the above fix and you're using an Ext Form/BasicForm make sure you set your method in the Form options, NOT the Action options. The same temp fix can be used for any of the adapters, just replace 'POST' with the bold text above.

tryanDLS
25 Apr 2007, 3:33 PM
Is it even valid to GET a form?

corey.gilmore
25 Apr 2007, 3:39 PM
Unless I'm totally misunderstanding how Ext Forms and Actions are meant to be used, it should be.
http://www.w3.org/TR/html4/interact/forms.html#h-17.3

Ext.lib.Ajax.formRequest() is called from within Ext.form.Action.Submit:


Ext.extend(Ext.form.Action.Submit, Ext.form.Action, {
type : 'submit',

run : function(){
var o = this.options;
var isPost = this.getMethod() == 'POST';
if(o.clientValidation === false || this.form.isValid()){
Ext.lib.Ajax.formRequest(
this.form.el.dom,
this.getUrl(!isPost),
this.createCallback(),
isPost ? this.getParams() : null, this.form.fileUpload, Ext.SSL_SECURE_URL);

}else if (o.clientValidation !== false){ // client validation failed
this.failureType = Ext.form.Action.CLIENT_INVALID;
this.form.afterAction(this, false);
}
},

MrKurt
25 Apr 2007, 4:05 PM
As I understand it, you can "GET" a form, but you need to append the data to the querystring rather than writing it to the request stream.

jack.slocum
26 Apr 2007, 11:11 AM
Can I ask why you would want to get a form over XHR? The only reason I can think of form GET with a form is to prevent the irritating "Data Expired" message with the back button. That wouldn't apply to XHR.

With all that said, I did apply your patch. :D

corey.gilmore
26 Apr 2007, 12:59 PM
Mostly I like to use GET to make troubleshooting easier; if I have
page.php?updateRecord?id=1&firstname=fname I can just browse to it and see the error immediately, and work on that page directly. Otherwise I have to dummy up the post which is a pain.

I'm not explictly using formRequest, it's called from Ext.form.Action.Submit.run() which I've extended to make success() meet my needs.

run : function(){
var o = this.options;
var isPost = this.getMethod() == 'POST';
if(o.clientValidation === false || this.form.isValid()){
Ext.lib.Ajax.formRequest(

I don't think that I'm Ext.form.Action.Submit incorrectly am I?