From 488759506b0f162051c83fd7f3ed34ea86e7e2e7 Mon Sep 17 00:00:00 2001 From: Toshaan Bharvani Date: Tue, 11 Jan 2022 17:53:41 +0100 Subject: [PATCH] change the form submission system to be uniform for the entire website Signed-off-by: Toshaan Bharvani --- themes/openpowerfoundation/assets/js/form.js | 97 +++++++++++++ .../layouts/contact/list.html | 22 +-- .../layouts/partials/contactform.html | 92 ++++++------ .../layouts/partials/footer.html | 9 +- .../layouts/partials/hubform.html | 134 +++++++++--------- 5 files changed, 236 insertions(+), 118 deletions(-) create mode 100644 themes/openpowerfoundation/assets/js/form.js diff --git a/themes/openpowerfoundation/assets/js/form.js b/themes/openpowerfoundation/assets/js/form.js new file mode 100644 index 0000000..44fcb67 --- /dev/null +++ b/themes/openpowerfoundation/assets/js/form.js @@ -0,0 +1,97 @@ +jQuery(document).ready(function($) { + "use strict"; + $(formname).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: submiturl, + complete: function() { + $("#sendmessage").addClass("show"); + $("#errormessage").removeClass("show"); + $('.contactForm').find("input, textarea").val(""); + if(goal) { + _paq.push(['trackGoal', goal]); + } + } + }); + return false; + } + }); +}); diff --git a/themes/openpowerfoundation/layouts/contact/list.html b/themes/openpowerfoundation/layouts/contact/list.html index e5d80d0..1df082d 100644 --- a/themes/openpowerfoundation/layouts/contact/list.html +++ b/themes/openpowerfoundation/layouts/contact/list.html @@ -1,13 +1,19 @@ {{ partial "header.html" . }} - {{ partial "navbar.html" . }} - -
- -{{ partial "contactform.html" . }} - +
+
+
+

{{ .Title }}

+
+
+
+ {{ .Content }} +
+
+ {{ partial "contactform.html" . }} +
+
+
-
- {{ partial "footer.html" . }} diff --git a/themes/openpowerfoundation/layouts/partials/contactform.html b/themes/openpowerfoundation/layouts/partials/contactform.html index 95572b5..dff3893 100644 --- a/themes/openpowerfoundation/layouts/partials/contactform.html +++ b/themes/openpowerfoundation/layouts/partials/contactform.html @@ -1,45 +1,57 @@
-
-
-
-
-
Your message has been sent. Thank you!
-
Error
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
- -
-
-
- -
-
-
- - -
-
+
+
+
Your message has been sent. Thank you!
+
Error
+
+
+
+ +
+
-
-
-
+
+
+ +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+ + +
+
+ +
+
diff --git a/themes/openpowerfoundation/layouts/partials/footer.html b/themes/openpowerfoundation/layouts/partials/footer.html index 41f7ad9..7b079d7 100644 --- a/themes/openpowerfoundation/layouts/partials/footer.html +++ b/themes/openpowerfoundation/layouts/partials/footer.html @@ -55,12 +55,9 @@ {{ $jqueryformjavascript := resources.Get "js/jquery.form.js" }} {{ $jqueryformjs := $jqueryformjavascript | resources.Minify }} -{{ $contactjavascript := resources.Get "js/contactform.js" }} -{{ $contactjs := $contactjavascript | resources.Minify }} - -{{ $hubrequestjavascript := resources.Get "js/hubrequestform.js" }} -{{ $hubrequestjs := $hubrequestjavascript | resources.Minify }} - +{{ $formjavascript := resources.Get "js/form.js" }} +{{ $formjs := $formjavascript | resources.Minify }} + {{ $changelogjavascript := resources.Get "js/changelog.js" }} {{ $changelogjs := $changelogjavascript | resources.Minify }} diff --git a/themes/openpowerfoundation/layouts/partials/hubform.html b/themes/openpowerfoundation/layouts/partials/hubform.html index 6cb0948..88f5648 100644 --- a/themes/openpowerfoundation/layouts/partials/hubform.html +++ b/themes/openpowerfoundation/layouts/partials/hubform.html @@ -1,70 +1,76 @@ {{ $hubdata := index $.Site.Data.hub }}
-
-
-
-
- - -
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-

What OpenPOWER resources do you require?

-
-
-
- {{ range $hubdata.accesstype }} - {{ .name }}
- {{ end }} -
-
- {{ range $hubdata.additions }} - {{ .name }}
- {{ end }} -
-
-
- -
-
-
- -
-
+
+
+ + +
+
+
+ +
+
+
+ +
+
-
-
-
+
+
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+
+

What OpenPOWER resources do you require?

+
+
+ {{ range $hubdata.accesstype }} + {{ .name }}
+ {{ end }} +
+
+ {{ range $hubdata.additions }} + {{ .name }}
+ {{ end }} +
+ +
+
+ +
+
+
+ +
+
+