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't matter if it can be set via GET, just need to make sure it is set both ways.
Thanks for the help!
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.
the form should set post do the get in the url
<form method="post" action="http://www.yourpage.php?firstparam=1&sec=2">
.
.
</form>
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()">