Add javascript code to keep input after redirect to the same jsp page

This commit is contained in:
Sofia Baltzi 2017-10-30 12:33:02 +00:00
parent b51e0c382d
commit f1cd4fffe8
3 changed files with 48 additions and 1 deletions

View File

@ -74,6 +74,7 @@ public class RegisterServlet extends HttpServlet {
// } else {
if (!ldapActions.usernameExists(username) && !ldapActions.emailExists(email)) {
ldapActions.createUser(username, email, firstName, lastName, organization/*, password*/);
logger.info("User successfully created");

View File

@ -55,7 +55,9 @@ public class RemindUsernameServlet extends HttpServlet {
String verificationCodeSubject = "Your OpenAIRE username";
emailSender.sendEmail(formEmail, verificationCodeSubject, verificationCodeMsg);
emailSender.sendEmail(formEmail, verificationCodeSubject, verificationCodeMsg);
response.sendRedirect("./emailSuccess.jsp");
} else {
request.getSession().setAttribute("message", "User not found");

View File

@ -221,6 +221,50 @@
$(".msg_pass_conf_error").fadeOut();
});
// Run on page load
window.onload = function() {
// // If sessionStorage is storing default values (ex. name), exit the function and do not restore data
// if (sessionStorage.getItem('name') == "name") {
// return;
// }
// If values are not blank, restore them to the fields
var first_name = sessionStorage.getItem('first_name');
if (first_name !== null) $('#first_name').val(first_name);
var last_name = sessionStorage.getItem('last_name');
if (last_name !== null) $('#last_name').val(last_name);
var organization = sessionStorage.getItem('organization');
if (organization !== null) $('#organization').val(organization);
var username = sessionStorage.getItem('username');
if (username !== null) $('#username').val(username);
var email = sessionStorage.getItem('email');
if (email !== null) $('#email').val(email);
var email_conf= sessionStorage.getItem('email_conf');
if (email_conf!== null) $('#email_conf').val(email_conf);
}
// Before refreshing the page, save the form data to sessionStorage
window.onbeforeunload = function() {
sessionStorage.setItem("first_name", $('#first_name').val());
sessionStorage.setItem("last_name", $('#last_name').val());
sessionStorage.setItem("organization", $('#organization').val());
sessionStorage.setItem("username", $('#username').val());
sessionStorage.setItem("email", $('#email').val());
sessionStorage.setItem("email_conf", $('#email_conf').val());
}
</script>
</div>
</ul>