繁体   English   中英

密码确认未触发

[英]Password confirmation not being fired

我在进行密码验证时遇到了一些麻烦,我认为现在已经正确定义了javascript,但是我无法验证表单成功,因为无论错误如何,它都会不断发布。

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
} 
@model Models.ResetModel

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">


$(document).ready(function () {
    $('#close').click(function (event) {
        closeAjax();

        event.cancelBubble = true;
        event.returnValue = false;
        event.preventDefault();
        event.stopPropagation();
    });
});

$(document).ready(function () {
    $("#resetForm").validate({
        rules: {
            password: {
                require: true, 
                minlength: 6
            },
            confirmpassword: {
                require: true,                     
                minlength: 6,
                equalTo: "#password"
            }
        },
        messages: {
            password: {
                require: "You must enter a password!",
                minlength: "Password must contain at least 6 characters"
                },
            confirmpassword: {
                require: "You must enter a password confirmation!",
                minlength: "Password must contain at least 6 characters",
                equalTo: "Password and Password Confirmation fields do not match!"
                }
        }
    });
});

这是HTML:

<div class="form_container">
<div class="logo">
    <a href=""><img class="logo" src="@Url.Content("~/Content/SP_Logo_white.png")" alt="SmartPlant Cloud"/></a>
</div>
    <div class="reset">
      <h3>Password Reset</h3>
    <div class="reset-help">
      <p>Forgot your password? Use the form to change or reset your password.</p>
    </div>
    @using (Html.BeginForm("Reset", "Reset", new { qString = Model.QueryString, @id = "resetForm" } ))
    {
    <label for="reset">UserName:</label>
    <input type="text" id="username" name="username" /><br />
    <label for="password">New Password:</label>
    <input type="password" id="password" name="password" /><br />
    <label for="confirmpassword">Confirm Password:</label>
    <input type="password" id="confirmpassword" name="confirmpassword" />
    <p><input type="submit" id="submit" value="Submit" /></p>
    }
</div>

您需要创建函数来验证表单客户端,如果输入的数据不正确,该客户端将返回值“ false”,因此不会提交from。 这不涉及PHP,而是在加载PHP之前就将其捕获。您也可以在服务器端进行验证检查。

   function Validate()
    {

        //insert javascript validation check

                return false;
                }

 <form onsubmit="return Validate();"  action="your.php" method="post" name="your name" >

 <label for="reset">UserName:</label>
<input type="text" id="username" name="username" /><br />
<label for="password">New Password:</label>
<input type="password" id="password" name="password" /><br />
<label for="confirmpassword">Confirm Password:</label>
<input type="password" id="confirmpassword" name="confirmpassword" />
<p><input type="submit" id="submit" value="Submit" /></p>
    </form>

希望这可以帮助。

暂无
暂无

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

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