Send both POST and GET in a form

烂漫一生 提交于 2019-11-28 23:41:13

Easy: Just specify the GET data in the form URL.

<form method="POST" action="form.php?a=1&b=2&c=3">

however, very carefully check how the data is used in the receiving script. Don't use $_REQUEST- rather parse $_GET and $_POST according to your exact needs and in the priority order you need them.

Make the form do a usual POST and use JavaScript to replicate the values in the query string as well:

HTML:

<form id="myform" method="post" action="..." onsubmit="process()">
  ...
</form>

JavaScript:

function process() {
  var form = document.getElementById('myform');
  var elements = form.elements;
  var values = [];

  for (var i = 0; i < elements.length; i++)
    values.push(encodeURIComponent(elements[i].name) + '=' + encodeURIComponent(elements[i].value));

  form.action += '?' + values.join('&');
}

Not sure what bug you're trying to get around but you can use jQuery to easily modify the form's action to contain the posted values:

script:

function setAction() {
    $("#myform").attr("action", "/path/to/script/?" + $("#myform").serialize());
}

html:

<form id="myform" action="/path/to/script/" method="post" onsubmit="setAction()">

the form should set post do the get in the url

<form method="post" action="http://www.yourpage.php?firstparam=1&sec=2">
.
.
</form>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!