0

I have a situation in which I am a bit confused on how to complete.

Example domains: http://url1.com http://url2.com

url1.com has a registration form url2.com has another form.

I need to pass the POST values from url1.com to url2.com without an actual submit happening. On url2.com I need to reconstruct the form with the POST values from url1.com and append hidden input values to the reconstructed form and then submit. I would like to completed this with JavaScript / jQuery if possible.

I would like to note that the url1.com contains a registration form with login and password.

Any advice is greatly appreciated.

Thanks in advance.

jeffreynolte
  • 3,654
  • 11
  • 36
  • 63

1 Answers1

1

Here is how you could post to another URL:

function post_to_url(path, params, method) {
    method = method || "post"; // Set method to post by default, if not specified.

    // The rest of this code assumes you are not using a library.
    // It can be made less wordy if you use one.
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);

    for(var key in params) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);

        form.appendChild(hiddenField);
    }

    document.body.appendChild(form);
    form.submit();
}

copied from here: JavaScript post request like a form submit

There are other solutions there as well.

P.S. Regarding the security question, read here: Are https URLs encrypted?

Essentially, all the data you pass over secure connections are encrypted, be it GET or POST. And be aware that even if you post data over regular http it could be intercepted by the man in the middle even if it is not visible for the user in the URL.

Community
  • 1
  • 1
Roman Goyenko
  • 6,524
  • 3
  • 44
  • 76
  • Submitting the form is not the issue, I would like to only pass the params to the second page without submitting them. – jeffreynolte Dec 13 '11 at 16:47
  • That's how you pass values - either submit them with POST or GET. You could pass in URL, like this url2.com?param1=value1&param2=value2&param3=value3 then on the url2.com the page that is addressed in the url can read the values from the url and put them in the form. – Roman Goyenko Dec 13 '11 at 19:31
  • That is what I am looking to do, I am quite sure there are issues with passing login and password data to a secondary page in a url. – jeffreynolte Dec 13 '11 at 20:13
  • you can post the way I wrote using the code above. To encrypt it you should use SSL, you set up SSL on the server of url2.com, browser will establish secure connection and all the data you pass from browser will be encrypted before you pass it. Even if you pass the data in URL as long as you have secure connection you will be ok, non-host part of the URL is encrypted, so could not be seen by man in the middle. – Roman Goyenko Dec 13 '11 at 21:39
  • I added more info in the end of the message about encrypting – Roman Goyenko Dec 13 '11 at 21:44