html - ASP Razor Web Pages - Form Submit is Moving My Data -
when submit login
email (aka username), want keep in login
form.
when submit register
email (aka username), want keep in register
form.
what happening is: when submit login
form, writes email (aka username) register
form. please see image happening.
@{ page.title = "login"; var username = ""; var password = ""; var errormessage = ""; var confirmpassword = ""; var regmsg = ""; var conftoken = ""; var emailbody = ""; var minpass = 2; var maxpass = 5; if (!ispost) { if (websecurity.isauthenticated) {errormessage = string.format("you logged in. (username: {0})", websecurity.currentusername);} } if(websecurity.isauthenticated){ errormessage = string.format("you logged in. (username: {0})", websecurity.currentusername); } if(ispost){ // login form if (request.form["loginsub"] != null){ regmsg = ""; username = request["username"]; password = request["password"]; if(websecurity.login(username,password,true)){ response.redirect("~/profile"); } else { errormessage = "invalid username or password. please try again."; } } // register form if (request.form["registersub"] != null){ websecurity.logout(); errormessage = ""; username = request["username"]; password = request["password"]; confirmpassword = request["confirmpassword"]; try { var mail = new system.net.mail.mailaddress(username); } catch { regmsg += "<br>invalid email format."; } if (password != confirmpassword) {regmsg += "</br>passwords don't match.";} if (websecurity.userexists(username)) {regmsg += string.format("</br>user '{0}' exists.", username);} if (password.length < minpass || password.length > maxpass) {regmsg += "</br>password doesn't meet length requirement.";} if (regmsg == "") { websecurity.createuserandaccount(username,password,null,false); //switch "true" token regmsg = string.format("{0} created.", username); response.write("<script>alert('email verification sent! please check email activate account.');</script>"); //response.write("<script>location.href = 'default.cshtml';</script>"); } } } } <style>header {visibility: hidden;}</style> <body> <h1>mysite</h1> <p> @if(errormessage != ""){<span>@html.raw(errormessage)</span>} @if(regmsg != ""){<span>@html.raw(regmsg)</span>} </p> <fieldset class="fs100"> <legend>login</legend> <form method="post" name="login"> @if(websecurity.isauthenticated){ <p>you logged in @websecurity.currentusername. <a href="@href("~/logout")">log out</a> </p> } <p> <label for="username">email address:</label><br/> <input type="text" name="username" id="username" value="" /> </p> <p> <label for="password">password:</label><br/> <input type="password" name="password" id="password" value="" /> </p> <p> <input type="submit" name="loginsub" value="submit" /> </p> <p><a href="@href("~/register")">forgot password?</a></p> </form> </fieldset> <fieldset> <legend>register</legend> <form method="post" name="register"> <p> <label for="username">email address:</label><br/> <input type="text" name="username" id="username" value='@request["username"]' /> </p> <p> <label for="password">password @minpass-@maxpass characters:</label><br/> <input type="password" name="password" id="password" value="" /> </p> <p> <label for="confirmpassword">confirm password:</label><br/> <input type="password" name="confirmpassword" id="confirmpassword" value="" /> </p> <p> <input type="submit" name="registersub" value="register" /> </p> </form> </fieldset> </body>
your code echoing value request in second form.
if don't want that, change code else.
you may want change each form have unique field names.
Comments
Post a Comment