表单验证无需重置(form validation without reset)
有没有办法检查表单发送到PHP页面的数据返回到表单页面没有重置发送的数据并显示错误?
该表格有20个字段,我需要在bd上检查其中的一个。 如果失败,用户可能被重定向到填充表单的表单页面,并在字段上显示错误消息,“错误”。
我想要一种技术的建议,而不是使用PHP填充每个字段。
更新:
我不想使用任何涉及重新填充字段的解决方案!
我想要一个解决方案返回到填充了先前值的表单页面。 我试过类似js.history.back或window.back()。 但表单返回空白...
更新 :如果你正在寻找这种类型的行为,现在有几种不同的技术来实现这一点。 我目前正在使用jQuery (Ajax)。
Is there a way to check the data sent by a form to a PHP page return to the form page WITHOUT resetting the data sent and show a error?
The form has 20 fields and I need to check one of them on a bd. If it fails the user may be redirected to the form page with the form populated and displaying a error message on the field which is 'wrong'.
I would like any advice of a technique instead of populating each field using PHP.
UPDATE:
I do not want to use any solution that involves repopulate the fields by myself!!!
I want a solution that return to the form page populated with the previous values. I've tried something like js.history.back or window.back(). But the form returns empty...
UPDATE: If you are looking for this type of behavior, nowadays there are several different techniques to achive this. I'm currently using jQuery (Ajax).
原文:https://stackoverflow.com/questions/2626113
更新时间:2020-01-27 07:50
最满意答案
在您的表单字段HTML中,将发布的值添加为字段值。
例如:
' />
In your form fields HTML, add posted values as field value.
e.g:
' />
2010-04-12
相关问答
这是因为重定向。 基本上,它重新加载页面。 您可以做的是,在验证表单之后,将输入的值放在会话变量中。 如果表单已正确验证且没有出现错误,则取消设置会话变量,否则,重定向并在视图页面上,默认情况下,在每个输入中放置您在会话var中的内容。 有点像这样: echo ' 希望能帮助到
...
我不确定通过重置表单了解你的意思。 以防万一... 你可以删除这样的验证.. $("form").removeData("validator");
$("form").removeData("unobtrusiveValidation");
I'm not sure I understand what you mean by reset the forms. Just in case... You can remove validation like this.. $("form").remov
...
如果要清除表单控件的touched和dirty标志,可以使用FormGroup 重置操作。 在内部,这将标记所有后代pristine和untouched 。 reset方法还会获取表单状态值的映射,以便您可以保留所有(或前一个表单提交中的某些值)。 看到这个例子 也来自你的问题: 因为我想显示成功插入的消息 表单重置不会影响您显示它,因为message属性不是表单的一部分 - 它只是组件上的常规属性。 You can use the FormGroup reset operation if you
...
更新: 我认为这更适合您的需求。 我已经更新了小提琴 https://jsfiddle.net/n7qqn1x6/6/ 在重置方法中调用$ setPristine并清除formData对象。 $scope.formData = {};
$scope.myForm.$setPristine();
为了在添加后从页面中删除错误消息,我必须使用ng-show而不是ng-if
a.resetForm();
}
Your problem is that resetForm is a method on the validator object returned by a.validate(...), and not on
...
你可以这样做(如果你有自定义错误就调整)...... form.find('label.error').remove();
You could do (adjust if you have custom errors)... form.find('label.error').remove();
最终成为一个equals / hashcode问题。 所以一定要检查那里! ended up being an equals/hashcode issue. So always be sure to check there!
我正在研究一个带淘汰和jquery验证的项目。 我已经解决的一件事是将用户输入划分为子部分,基本上在同一页面上有多个表单。 将它们组合在一起,这就是用户看到的总“形式”。 (旁白:我这样做是因为我提交的API对表单/ UI /营销部门对用户体验的期望有不同的期望。每个
本质上是一个不同的API输入部分,但是营销dept希望能够任意订购用户输入,所以我按类收集它们:... some inputs
...