简体   繁体   English

提交表单及其数据到外部URL以及重定向

[英]Submit Form and it's Data to Outside URL as well as redirecting

I am trying to make a login form on the front end of my site that will take the username and password and submit to an outside URL (a portal for the customers). 我正在尝试在网站的前端制作一个登录表单,该表单将使用用户名和密码并提交到外部URL(客户门户)。 I want the data they sumbit to the form on my website to pass to the new URL with the portal and attempt to log them in. Right now, nothing is happening and I can't figure out what is happening. 我希望它们汇总到我网站上的表单的数据通过门户传递到新的URL并尝试登录。现在,什么都没有发生,我也不知道发生了什么。 Currently, when I submit the form, it just appends to my current URL with the POST data from the form it doesnt attempt to send the data to the outside URL neither does it re direct. 当前,当我提交表单时,它只是将表单中的POST数据附加到我当前的URL中,它不会尝试将数据发送到外部URL,也不会重定向。

HTML: HTML:

<form id="redirect-form">
 <p class="mbn"><input type="text" name="loginid" placeholder="username" /></p>
 <p class="mbn"><input type="password" name="password" placeholder="password" /></p>
 <p> <button type="submit" onclick="javascript:register()">Sign In</button></p>
</form>

JS: JS:

function register() {
    form=document.getElementById('redirect-form');
    form.target='_blank';
    form.action='https://pathtomyportal.com';
    form.submit();
}

Change your form method to POST . 将表单方法更改为POST

<form id="redirect-form" method="POST">
 <p class="mbn"><input type="text" name="loginid" placeholder="username" /></p>
 <p class="mbn"><input type="password" name="password" placeholder="password" /></p>
 <p> <button type="submit" onclick="javascript:register()">Sign In</button></p>
</form>

Your Javascript is valid and working fine for me. 您的Javascript有效,并且对我来说很好用。 It sending post data to server side. 它将post数据发送到服务器端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM