由于对JS和Jquery不好,我正在努力向Marketo表单添加新的验证规则,当尝试提交表单时显示错误消息,任何字段都是空的,我需要验证FirstName和LastName字段仅允许字母字符,并且在输入数字字符时应通过错误消息。 以下是我的Marketo LP:http://qliktest.qlik.com/Vinu-Test1_Reg_Form.html
答案 0 :(得分:0)
如果您在Marketo中将字段标记为“必需”,则已经内置了逻辑,可以为您进行验证。如果要创建一些自定义验证逻辑,请参阅I.E.只允许字段中的字母字符,您需要使用Marketo Forms 2.0 Javascript API(http://developers.marketo.com/documentation/websites/forms-2-0/)
以下是使用API验证Marketo表单字段的示例:
MktoForms2.whenReady(function(form){
//listen for the validate event form.onValidate(function() { // Get the values var vals = form.vals(); //Check your condition if (vals.Country == "USA" && vals.vehicleSize != "Massive") { // Prevent form submission form.submittable(false); // Show error message, pointed at VehicleSize element var vehicleSizeElem = form.getFormElem().find("#vehicleSize"); form.showErrorMessage("All Americans must have a massive vehicle", vehicleSizeElem); } else { // Enable submission for those who met the criteria form.submittable(true); } }); });
答案 1 :(得分:0)
这是自定义电子邮件验证的示例。您可以将自定义代码放入whenReady函数中。
MktoForms2.whenReady(function(form) {
function isEmailValid(email) {
RE_EMAIL_ASCII_PUBLIC = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/;
return RE_EMAIL_ASCII_PUBLIC.test(email);
}
form.onValidate(function() {
var values = form.vals();
if (values.Email) {
if (!isEmailValid(values.Email)) {
form.submitable(false);
var emailElem = form.getFormElem().find("#Email");
form.showErrorMessage(
// write your message here
"Must be valid email.",
emailElem
);
} else {
form.submitable(true);
}
}
});