如果客户端验证文本相同并显示,如何不显示服务器端验证消息?

时间:2021-09-10 15:49:33

I have several divs with client side class validation-failure in a page like below. The text in between can change from div to div.

我有几个div与客户端类验证失败在如下页面中。中间的文本可以从div更改为div。

<div class="validation-failure">At least one of the above 2 fields needs to be entered</div>

I also have server side validation errors displayed in website as below

我也在网站上显示服务器端验证错误,如下所示

<div id="messages_product_error_view">
        <ul>
            <li>At least one of the above 2 fields needs to be entered</li>        </ul>
    </div>

Now I want to make sure that when client side validation is displayed and the text is same as the server side validation then only client side validation is shown. However, if client side validation error is empty div then show the server side validation. I think it can be done through jquery.. please help?

现在我想确保在显示客户端验证并且文本与服务器端验证相同时,仅显示客户端验证。但是,如果客户端验证错误为空div,则显示服务器端验证。我认为可以通过jquery来完成..请帮忙?

Hi

I want to capture as soon as any text shows up on a div.

我想在任何文本显示在div上时捕获。

This is what is happening.

这就是正在发生的事情。

As user types on an input field, client side js kicks in and shows client side js validation errors messages.

当用户在输入字段上键入时,客户端js会启动并显示客户端js验证错误消息。

However, in some rare cases they have been able to bypass the js or the js validation is just not right. So server side validation logic have been put in place using php.

然而,在一些罕见的情况下,他们已经能够绕过js或js验证是不对的。所以服务器端验证逻辑已经使用php实现。

Now when types something on the input field, the client side validation kicks in.. and if user presses submit, the server side validatiojn also shows up..

现在,当在输入字段上键入内容时,客户端验证将启动..如果用户按下提交,服务器端validatiojn也会显示..

I want just client side to show up .. if client side not there then show up server side....The soln you proposed works.. but in a page if user keeps on typing wrong input the client site validation message again keeps on coming with server side still there. So need to somehow detect when user types anything on input and then if client side validation shows up then dont display server side

我想只是客户端出现..如果客户端不在那里然后显示服务器端....你提出的解决方案..但在页面中,如果用户继续输入错误的输入,客户端站点验证消息再次保持服务器端仍然存在。因此,需要以某种方式检测用户何时输入任何内容,然后如果客户端验证显示,则不显示服务器端

1 个解决方案

#1


1  

var clientSide = $(".validation-failure");
var serverSide = $("#messages_product_error_view li");

if (serverSide.text() == clientSide.text()) {
    serverSide.hide();
    clientSide.show();
} else if (clientSide.text().length == 0) {
    serverSide.show();
    clientSide.hide();
}

#1


1  

var clientSide = $(".validation-failure");
var serverSide = $("#messages_product_error_view li");

if (serverSide.text() == clientSide.text()) {
    serverSide.hide();
    clientSide.show();
} else if (clientSide.text().length == 0) {
    serverSide.show();
    clientSide.hide();
}