I need to make a form send both POST and GET requests (due to some bugs in IE and iframes), how can you do so?
The data being sent is nothing mega secure so it doesn
If you need a dynamicaly created URL. You can use this HTML example. The GET fields are in a seprated Form. Before submit of the POST Form the URL is generated from the GET Form.
<form id="formGET">
email: <input name="email" value="email@domain.nl"/>
</form>
<form id="formPOST" method="post" onsubmit="this.action='/api/Account?'+Array.prototype.slice.call(formGET.elements).map(function(val){return val.name + '=' + val.value}).join('&');">
mobile: <input name="mobile" value="9999999999" /><br />
<button>POST</button>
</form>
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()">
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('&');
}
the form should set post do the get in the url
<form method="post" action="http://www.yourpage.php?firstparam=1&sec=2">
.
.
</form>
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.