redirect_by_post
function to redirect a webpage to another using post method
by cgarciagl
HTML
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/themes/south-street/jquery-ui.css">
<div class='ui-state-highlight ui-corner-all'>
in the server there is only a <br/> <br/> < ? php print_r($_POST) ? >
<br/> <br/>
So you can send any variables
</div>
<button id="btn">go an check the variables sent by post</button>
CSS
.ui-state-highlight {width:200px;margin:20px; padding:20px;}
JavaScript
/* need JQuery */
/* function to redirect a webpage to another using post method */
function redirect_by_post(purl, pparameters, in_new_tab) {
pparameters = (typeof pparameters == 'undefined') ? {} : pparameters;
in_new_tab = (typeof in_new_tab == 'undefined') ? true : in_new_tab;
var form = document.createElement("form");
$(form).attr("id", "reg-form").attr("name", "reg-form").attr("action", purl).attr("method", "post").attr("enctype", "multipart/form-data");
if (in_new_tab) {
$(form).attr("target", "_blank");
}
$.each(pparameters, function(key) {
$(form).append('<input type="text" name="' + key + '" value="' + this + '" />');
});
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
return false;
}
$('#btn').button().click(function() {
redirect_by_post('http://pamppi.info/jotform-testing/thankyou/postvars.php', {
variable1: 'Carlos',
variable2: 'Garcia'
}, true);
});