0

How can I define additional url parameters for my POST form submission?

This is how I load my form:

form.load({
    url:APIURI+'GetComment',
    method:'GET',
    params:params,
});

Result: The params object is serialized into GET parameters; the form content is returned as JSON.

This is how I submit my form:

form.submit({
    url:APIURI+'SetComment',
    method:'POST',
    params:params,
    callback:function() {
        me.close();
    }
});

Expected result: The form data should be sent as JSON POSTDATA, and the params should be sent as GET parameters.

Actual result: The form data was made an object; then the params were applied to that very object - and some of them overrode form fields which go by the same name.

What I also tried: I tried to put the params into the options object as urlParams, baseParams and extraParams, but none of these work.

Alexander
  • 19,906
  • 19
  • 75
  • 162
  • Maybe try using `Ext.Ajax.request()`. Similar like in [this](http://stackoverflow.com/questions/2917581/how-to-post-json-data-with-extjs) question. – Bojan Dević Feb 11 '16 at 14:49
  • @BojanDević Well, that does not help with submission of the form. I would have to manually collect the form data form submission then, manually validate it and so on... – Alexander Feb 11 '16 at 15:09
  • but thats just `form.isValid()` and `form.getValues()`. – Bojan Dević Feb 11 '16 at 16:01
  • 1
    You could serialize params and append the string to the url, for example: `Ext.Object.toQueryString(params)` – tonymayoral Feb 11 '16 at 16:32
  • @tonymayoral Digging through the `form.submit()` code, I found no possibility to inject parameters into the url. So I guess your proposed way is the only feasible one. Please make it an answer for me to accept. – Alexander Feb 11 '16 at 17:04

1 Answers1

1

You could serialize params and append the string to the url, such as:

form.submit({
  url: APIURI + 'SetComment?' + Ext.Object.toQueryString(params),
  method: 'POST',
  callback: function() {
    me.close();
  }
});
tonymayoral
  • 4,797
  • 2
  • 26
  • 27