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!
You cannot send the values of some input fields via GET and others via POST with PHP and HTML. If you add JavaScript, you could add the values of some input fields to the query string of the action-attribute of the form.
With Ajax you can send data to a PHP script via GET and POST in the same request. The process is similar to sending data through the POST, it's actually the same, being only applied a "trick". - the values to be sent with POST method are added in the parameter of the "send()" function.
The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute). The form-data can be sent as URL variables (with method="get" ) or as HTTP post transaction (with method="post" ). Notes on GET: Appends form-data into the URL in name/value pairs.
If you are working RESTfully, GET should be used for requests where you are only getting data, and POST should be used for requests where you are making something happen.
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('&');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With