我对HTML编码很新。经过几个小时的互联网搜索后,我失败了,所以我在这里。我在这里设置了CSRF概念验证页面,我希望它重定向到另一个页面,该页面将执行CSRF已实现的有效负载。
<html>
<body>
<form action="https://website.com/action.php?" method="POST">
<input type="hidden" name="fullname" value="john" />
<input type="hidden" name="address" value="street 2, 32 ave" />
<input type="submit" value="Submit request" />
</form>
</body>
</html>
因此,在使用此表单提交后,它所做的只是重定向到此页面
但不是这样,我希望它重定向到另一个URL并提交该表单。
答案 0 :(得分:12)
对于其他遇到同样问题的人,我自己也明白了。
<html>
<body>
<form target="_blank" action="https://website.com/action.php" method="POST">
<input type="hidden" name="fullname" value="Sam" />
<input type="hidden" name="city" value="Dubai " />
<input onclick="window.location.href = 'https://website.com/my-account';" type="submit" value="Submit request" />
</form>
</body>
</html>
我所要做的就是添加目标=&#34; _blank&#34;属性为内联在窗体上以在新页面中打开响应,并使用onclick在提交按钮上重定向其他页面。
答案 1 :(得分:4)
您需要使用jQuery AJAX或XMLHttpRequest()将数据发布到服务器。数据发布后,您可以通过window.location.href
将页面重定向到另一个页面。
示例:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
window.location.href = 'https://website.com/my-account';
}
};
xhttp.open("POST", "demo_post.asp", true);
xhttp.send();
答案 2 :(得分:0)
您可以做的是验证值,例如:
如果fullanme输入的值大于某个值的长度,并且如果address输入的值大于某个值的长度,则重定向到新页面,否则显示输入错误。
// We access to the inputs by their id's
let fullname = document.getElementById("fullname");
let address = document.getElementById("address");
// Error messages
let errorElement = document.getElementById("name_error");
let errorElementAddress = document.getElementById("address_error");
// Form
let contactForm = document.getElementById("form");
// Event listener
contactForm.addEventListener("submit", function (e) {
let messageName = [];
let messageAddress = [];
if (fullname.value === "" || fullname.value === null) {
messageName.push("* This field is required");
}
if (address.value === "" || address.value === null) {
messageAddress.push("* This field is required");
}
// Statement to shows the errors
if (messageName.length || messageAddress.length > 0) {
e.preventDefault();
errorElement.innerText = messageName;
errorElementAddress.innerText = messageAddress;
}
// if the values length is filled and it's greater than 2 then redirect to this page
if (
(fullname.value.length > 2,
address.value.length > 2)
) {
e.preventDefault();
window.location.assign("https://www.google.com");
}
});
.error {
color: #000;
}
.input-container {
display: flex;
flex-direction: column;
margin: 1rem auto;
}
<html>
<body>
<form id="form" method="POST">
<div class="input-container">
<label>Full name:</label>
<input type="text" id="fullname" name="fullname">
<div class="error" id="name_error"></div>
</div>
<div class="input-container">
<label>Address:</label>
<input type="text" id="address" name="address">
<div class="error" id="address_error"></div>
</div>
<button type="submit" id="submit_button" value="Submit request" >Submit</button>
</form>
</body>
</html>