2

I have form with username and password. when i click on submit buttom then username and password will pass to another page and open new window.

i know that i will pass this data by GET request like

window.open('url.php?unm=username&pass=password','_blank');

but in my case i don't want to display data in url. I want to use POST Method To get data in url.php page.

So How to do this. Please Help.. Thanks For Advance

Below Code I use :

$.post("url.php?unm=username&pass=password",function(data){
    $("#form").hide();
});
Sachin Sanchaniya
  • 996
  • 1
  • 8
  • 16

4 Answers4

1

You need to do with form submit and then open new window

<form id="Form" method="post" action="url.php" target="TheWindow">
<input type="hidden" name="unm" value="" />
<input type="hidden" name="pass" value="" />
</form>
<script>
function Post(name,password) {
  var f = document.getElementById('Form');
  f.unm.value = name;
  f.pass.value = password;
  window.open('', 'TheWindow');
  f.submit();
} 
Post("username","password");
</script>
Jack jdeoel
  • 4,554
  • 5
  • 26
  • 52
0

You can do this by Javascript. See example below.Source

var redirect = function(url, method) {
    var form = document.createElement('form');
    form.method = method;
    form.action = url;
    form.submit();
};

redirect('http://www.example.com', 'post');
Community
  • 1
  • 1
TIGER
  • 2,864
  • 5
  • 35
  • 45
0
<form action="url.php" type="post">
    <input type="hidden" value="username" name="unm">
    <input type="hidden" value="password" name="pass">
    <button type="submit">
</form>

you can fetch the data from url.php like

$username = $_POST['unm']; $password = $_POST['pass'];

Mohamed Athif
  • 468
  • 2
  • 6
  • 19
0

Please try this.

<script>
$(document).ready(function(){
    $("button[name='loginBtn']").click(function(){
        $('#frm_RegisteredForm').attr('action','test.php');
        $('#frm_RegisteredForm').submit();
    });
});
</script>

<form name="frm_RegisteredForm" id="frm_RegisteredForm" action="javascript:void(0);" autocomplete="off" method="post"  target='_blank'>
    <input type="text" name="password" id="password" value="" />
    <input type="text" name="username" id="username" value="" /> 
    <button type="button"  name="loginBtn" id="loginBtn" value="Add" accesskey="a">login</button>
</form>

Here I'm submitting my form from java script IE I'm using jQuery. To open new page I'm just specified the target of the form as blank in form tag it self. Try this. This will work for you too. This is working in my case.

MeSo2
  • 450
  • 1
  • 7
  • 18
Pranav MS
  • 2,235
  • 2
  • 23
  • 50