我想有我自己的验证流程,自定义布局和消息。默认情况下,来自表单构建器的验证将所有错误消息放在输入字段旁边。它将在提交后立即验证所有字段。
我想在提交后逐个验证字段,所有输入字段的错误消息都显示在相同的位置(表单顶部的submit按钮旁边)。
目前,我正在尝试"ASCX“类型的自定义表单布局。是否可以在后端代码".cs“中执行所有验证?
或者我必须在自定义表单布局设计中以源代码模式注入java脚本?
还有没有更好的方法呢?
发布于 2017-03-14 12:24:37
在HTML布局类型中,您可以将验证宏放置在需要-> $$validation:FirstName$$的任何位置
还可以指定在不提交表单的情况下执行的验证-示例-> http://devnet.kentico.com/articles/tweaking-kentico-(2)-unique-fields
无论如何,使用上面的验证宏,您可以将错误消息移动到您想要的任何位置。
发布于 2017-03-14 12:35:40
在联机表单中,转到“布局”,然后使用HTML和用于表单字段值、标签和验证的宏手动输入布局标记。在这里,您可以指定所有表单元素在表单上的位置,甚至按钮。
如果您希望有自定义CS来验证表单,最好在插入之前为表单创建一个自定义事件处理程序。请参阅下面的文档:
using CMS;
using CMS.DataEngine;
using CMS.OnlineForms;
using CMS.Helpers;
// Registers the custom module into the system
[assembly: RegisterModule(typeof(CustomFormModule))]
public class CustomFormModule : Module
{
// Module class constructor, the system registers the module under the name "CustomForms"
public CustomFormModule()
: base("CustomForms")
{
}
// Contains initialization code that is executed when the application starts
protected override void OnInit()
{
base.OnInit();
// Assigns a handler to the Insert.After event
// This event occurs after the creation of every new form submission
BizFormItemEvents.Insert.After += Insert_After;
}
private void Insert_After(object sender, CMS.OnlineForms.BizFormItemEventArgs e)
{
if (e.Item.TypeInfo.ObjectType.ToLower().Contains("bizform.codename"))
{
//do some work or form validation
}
}
}
https://stackoverflow.com/questions/42781557
复制