forked from website/openpower.foundation
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.4 KiB
JavaScript
96 lines
2.4 KiB
JavaScript
4 years ago
|
jQuery(document).ready(function($) {
|
||
|
"use strict";
|
||
|
$('form.contactForm').submit(function() {
|
||
|
var f = $(this).find('.form-group'),
|
||
|
ferror = false,
|
||
|
emailExp = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i;
|
||
|
f.children('input').each(function() {
|
||
|
var i = $(this);
|
||
|
var rule = i.attr('data-rule');
|
||
|
if (rule !== undefined) {
|
||
|
var ierror = false;
|
||
|
var pos = rule.indexOf(':', 0);
|
||
|
if (pos >= 0) {
|
||
|
var exp = rule.substr(pos + 1, rule.length);
|
||
|
rule = rule.substr(0, pos);
|
||
|
} else {
|
||
|
rule = rule.substr(pos + 1, rule.length);
|
||
|
}
|
||
|
switch (rule) {
|
||
|
case 'required':
|
||
|
if (i.val() === '') {
|
||
|
ferror = ierror = true;
|
||
|
}
|
||
|
break;
|
||
|
case 'minlen':
|
||
|
if (i.val().length < parseInt(exp)) {
|
||
|
ferror = ierror = true;
|
||
|
}
|
||
|
break;
|
||
|
case 'email':
|
||
|
if (!emailExp.test(i.val())) {
|
||
|
ferror = ierror = true;
|
||
|
}
|
||
|
break;
|
||
|
case 'checked':
|
||
|
if (!i.attr('checked')) {
|
||
|
ferror = ierror = true;
|
||
|
}
|
||
|
break;
|
||
|
case 'regexp':
|
||
|
exp = new RegExp(exp);
|
||
|
if (!exp.test(i.val())) {
|
||
|
ferror = ierror = true;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
i.next('.validation').html((ierror ? (i.attr('data-msg') !== undefined ? i.attr('data-msg') : 'wrong Input') : '')).show('blind');
|
||
|
}
|
||
|
});
|
||
|
f.children('textarea').each(function() {
|
||
|
var i = $(this);
|
||
|
var rule = i.attr('data-rule');
|
||
|
if (rule !== undefined) {
|
||
|
var ierror = false;
|
||
|
var pos = rule.indexOf(':', 0);
|
||
|
if (pos >= 0) {
|
||
|
var exp = rule.substr(pos + 1, rule.length);
|
||
|
rule = rule.substr(0, pos);
|
||
|
} else {
|
||
|
rule = rule.substr(pos + 1, rule.length);
|
||
|
}
|
||
|
switch (rule) {
|
||
|
case 'required':
|
||
|
if (i.val() === '') {
|
||
|
ferror = ierror = true;
|
||
|
}
|
||
|
break;
|
||
|
case 'minlen':
|
||
|
if (i.val().length < parseInt(exp)) {
|
||
|
ferror = ierror = true;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
i.next('.validation').html((ierror ? (i.attr('data-msg') != undefined ? i.attr('data-msg') : 'wrong Input') : '')).show('blind');
|
||
|
}
|
||
|
});
|
||
|
if (ferror) {
|
||
|
return false;
|
||
|
} else {
|
||
|
var str = $(this).serialize();
|
||
|
$.ajax({
|
||
|
type: "POST",
|
||
|
data: str,
|
||
|
url: contacturl,
|
||
|
complete: function() {
|
||
|
$("#sendmessage").addClass("show");
|
||
|
$("#errormessage").removeClass("show");
|
||
|
$('.contactForm').find("input, textarea").val("");
|
||
|
_paq.push(['trackGoal', 99]);
|
||
|
}
|
||
|
});
|
||
|
return false;
|
||
|
}
|
||
|
});
|
||
|
});
|