Reputation: 235
I am need to submit an form through an link tag to spring security validation, but that is not working. Code is below:
<html>
<body>
<form id="login" method="post" action="/j_spring_security_check">
<fieldset>
<input id="username" name="j_username" type="text"/>
<input id="password" name="j_password" type="password"/>
</fieldset>
<fieldset>
<input type="submit" value="Submit"/>
<a href="" onclick="postForm();">Demo</a>
</fieldset>
</form>
<script type="text/javascript">
function postForm()
{
document.getElementById("username").innerHTML="demo";
document.getElementById("password").innerHTML="demo";
document.getElementById("login").submit();
}
</script>
</body>
</html>
Here when user click Demo link it should authorise and divert to demo page, but its not posting to spring security, while I submit through button is working. How can I authorize through an HTML link?
Upvotes: 0
Views: 835
Reputation: 388356
You need to prevent the default action of the anchor
element
<a href="#" onclick="return postForm();">Demo</a>
And
<script type="text/javascript">
function postForm()
{
document.getElementById("username").value="demo";
document.getElementById("password").value="demo";
document.getElementById("login").submit();
return false;
}
</script>
Demo: Plunker
Upvotes: 1