0

Is it possible that, a form contains multiple inputs, when submit the form, some input values go into post body while some go into the URL?

<form action=sample.php method=POST accept-charset=gbk>
  <input name=a />
  <input name=b />
</form>

And when submit, it POST b=someval to sample.php?a=itsval

——

I’m handling an old system. The backend read parameters some from get, some from post, and not using utf-8. No one can change its code.

tsh
  • 4,263
  • 5
  • 28
  • 47
  • Possible duplicate of https://stackoverflow.com/questions/1592418/mixing-get-with-post-is-it-a-bad-practice – Jordan Quartermain Jul 11 '18 at 23:07
  • Not the same, that question do not need user inputed values in get url. – tsh Jul 11 '18 at 23:24
  • But the answer to your question is 'yes', you can mix the two. – Jordan Quartermain Jul 12 '18 at 01:17
  • @JordanQuartermain So, _how_? It don't answer this question, even don't answer it in yes or no. I did read that post. Codes from that answer puts GET parameters in the action attribute. But that won't work on my situation: These GET parameters should be read from user input. That is quite a huge difference. I don't see an easy way to archive this by that code. – tsh Jul 12 '18 at 02:13
  • You'll have to manipulate the form submission with Javascript before it's sent. For example, you could get all the parameters you need to submit via GET method, change the form action attr to reflect these values, then submit the form as normal. I've done this once in the past with success. If I have time, I'll quickly write up some code. Sorry about the ambiguity of my comments earlier, I'm just at work and I don't have much time on my hands today haha :) – Jordan Quartermain Jul 12 '18 at 03:00
  • @JordanQuartermain Not quite easy till. Before I modify the `action` attribute. I need encode the value user input. `encodeURIComponent` only works on UTF-8. But I need other charset. And `TextEncoder` also dropped ability to encode strings in another charset. After some research, using accept-charset maybe the best way to handle this. – tsh Jul 12 '18 at 03:09

0 Answers0