Last modified by Alex Cotiugă on 2026/05/02 12:23

From version 13.60
edited by Alex Cotiugă
on 2026/05/02 07:40
Change comment: There is no comment for this version
To version 13.86
edited by Alex Cotiugă
on 2026/05/02 08:12
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -39,7 +39,7 @@
39 39   </dl>
40 40   <p>Your information will only be used to respond to this request.</p>
41 41   ##<p>Your information will only be used to respond to this request. See the Privacy Policy for details.</p>
42 - <input id="contactSubmit" type="submit" class="btn btn-primary" value="Send my request" disabled="disabled">
42 + <input id="contactSubmit" type="submit" class="btn btn-primary" value="Send my request">
43 43   </form>
44 44   </div>
45 45   <div class="col-xs-5">
... ... @@ -62,6 +62,18 @@
62 62   <li>If useful, we schedule a short call to discuss scope, timeline, and estimated effort.</li>
63 63   </ol>
64 64   </div>
65 + <div class="reviewNotifications">
66 + <div class="hidden reviewNotificationSuccess">
67 +
68 + {{success}}reviewNotification{{/success}}
69 +
70 + </div>
71 + <div class="hidden reviewNotificationError">
72 +
73 + {{error}}reviewNotification{{/error}}
74 +
75 + </div>
76 + </div>
65 65   </div>
66 66   </div>
67 67  {{/html}}
XWiki.JavaScriptExtension[0]
code
... ... @@ -1,8 +1,14 @@
1 1  require(['jquery'], function ($) {
2 2   var serviceURL = new XWiki.Document('WebHome', 'content').getURL('get', 'xpage=plain');
3 - var form = $('#agneaseContactForm');
4 - var submitButton = $('#agneaseContactSubmit');
3 + var form = $('#contactForm');
4 + var submitButton = $('#contactSubmit');
5 5  
6 + var successBox = $('.reviewNotificationSuccess');
7 + var errorBox = $('.reviewNotificationError');
8 +
9 + var nameFieldName = 'Agnease.Code.ContactForm.ContactFormClass_0_name';
10 + var emailFieldName = 'Agnease.Code.ContactForm.ContactFormClass_0_email';
11 +
6 6   function getFormData() {
7 7   var data = {};
8 8  
... ... @@ -9,10 +9,26 @@
9 9   $.each(form.serializeArray(), function (_, field) {
10 10   data[field.name] = field.value;
11 11   });
18 + console.log(data)
12 12  
13 13   return data;
14 14   }
15 15  
23 + function isValidEmail(value) {
24 + return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
25 + }
26 +
27 + function updateSubmitState() {
28 + var data = getFormData();
29 + var name = $.trim(data[nameFieldName] || '');
30 + var email = $.trim(data[emailFieldName] || '');
31 +
32 + submitButton.prop('disabled', !(name.length > 0 && isValidEmail(email)));
33 + }
34 +
35 + form.on('input change keyup', 'input, textarea, select', updateSubmitState);
36 + updateSubmitState();
37 +
16 16   form.on('submit', function (event) {
17 17   event.preventDefault();
18 18  
... ... @@ -22,21 +22,24 @@
22 22  
23 23   $.post({
24 24   url: serviceURL,
25 - data: data,
26 - dataType: 'json'
47 + data: data
27 27   }).done(function (response) {
28 - alert(response.message || 'Your request was sent successfully.');
49 + // replace with succcess message alert(response.message || 'Your request was sent successfully.');
50 + //var message = 'The request could not be sent. Please try again or contact Agnease by email.';
51 + var successBoxContent = successBox.find('.box div p');
52 + successBoxContent.text(data.message);
53 + successBox.toggleClass('hidden');
54 + if (errorBox.is(':visible')) {
55 + errorBox.toggleClass('hidden');
56 + }
29 29   form[0].reset();
30 30   }).fail(function (xhr) {
31 - var message = 'The request could not be sent. Please try again or contact Agnease by email.';
32 -
33 - if (xhr.responseJSON && xhr.responseJSON.message) {
34 - message = xhr.responseJSON.message;
35 - } else if (xhr.responseText) {
36 - message = xhr.responseText;
59 + var errorBoxContent = errorBox.find('.box div p');
60 + errorBoxContent.text(xhr.responseJSON.message);
61 + errorBox.toggleClass('hidden');
62 + if (successBox.is(':visible')) {
63 + successBox.toggleClass('hidden');
37 37   }
38 -
39 - alert(message);
40 40   submitButton.prop('disabled', false);
41 41   });
42 42   });