Last modified by Alex Cotiugă on 2026/05/04 06:15

From version 13.152
edited by Alex Cotiugă
on 2026/05/02 08:58
Change comment: There is no comment for this version
To version 13.95
edited by Alex Cotiugă
on 2026/05/02 08:17
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,21 +19,3 @@
1 -{{velocity wiki="false"}}
2 -#if ($xcontext.action == 'get')
3 - #set ($message = '')
4 - #set ($contactFormEntryDoc = $xwiki.getDocument('ContactFormEntries' + $java.util.UUID.randomUUID()))
5 - #set ($statusCode = 200)
6 -
7 - #foreach ($parameterName in $request.parameterNames)
8 - #set ($message = "$message $parameterName")
9 - #end
10 -
11 - ##set ($statusCode = 400)
12 - ##set ($message = 'error')
13 -
14 - #set ($discard = $response.setStatus($statusCode))
15 - #jsonResponse({'message': $message})
16 -#end
17 -{{/velocity}}
18 -
19 19  {{velocity}}
20 20  #set ($discard = $xwiki.ssx.use('contact.WebHome'))
21 21  #set ($xobject = $doc.getObject('Agnease.Code.ContactForm.ContactFormClass'))
... ... @@ -59,22 +59,6 @@
59 59   ##<p>Your information will only be used to respond to this request. See the Privacy Policy for details.</p>
60 60   <input id="contactSubmit" type="submit" class="btn btn-primary" value="Send my request">
61 61   </form>
62 - {{/html}}
63 - {{html clean="false" wiki="true"}}
64 - <div class="reviewNotifications">
65 - <div class="hidden reviewNotificationSuccess">
66 -
67 - {{success}}reviewNotification{{/success}}
68 -
69 - </div>
70 - <div class="hidden reviewNotificationError">
71 -
72 - {{error}}reviewNotification{{/error}}
73 -
74 - </div>
75 - </div>
76 - {{/html}}
77 - {{html clean="false"}}
78 78   </div>
79 79   <div class="col-xs-5">
80 80   <div class="widget">
... ... @@ -96,6 +96,20 @@
96 96   <li>If useful, we schedule a short call to discuss scope, timeline, and estimated effort.</li>
97 97   </ol>
98 98   </div>
65 + {{/html}}
66 + {{html clean="false" wiki="true"}}
67 + <div class="reviewNotifications">
68 + <div class="hidden reviewNotificationSuccess">
69 +
70 + {{success}}reviewNotification{{/success}}
71 +
72 + </div>
73 + <div class="hidden reviewNotificationError">
74 +
75 + {{error}}reviewNotification{{/error}}
76 +
77 + </div>
78 + </div>
99 99   </div>
100 100   </div>
101 101  {{/html}}
XWiki.JavaScriptExtension[0]
code
... ... @@ -1,5 +1,5 @@
1 1  require(['jquery'], function ($) {
2 - var serviceURL = new XWiki.Document('WebHome', 'contact').getURL('get');
2 + var serviceURL = new XWiki.Document('WebHome', 'content').getURL('get', 'xpage=plain');
3 3   var form = $('#contactForm');
4 4   var submitButton = $('#contactSubmit');
5 5  
... ... @@ -6,13 +6,44 @@
6 6   var successBox = $('.reviewNotificationSuccess');
7 7   var errorBox = $('.reviewNotificationError');
8 8  
9 + var nameFieldName = 'Agnease.Code.ContactForm.ContactFormClass_0_name';
10 + var emailFieldName = 'Agnease.Code.ContactForm.ContactFormClass_0_email';
11 +
12 + function getFormData() {
13 + var data = {};
14 +
15 + $.each(form.serializeArray(), function (_, field) {
16 + data[field.name] = field.value;
17 + });
18 + console.log(data)
19 +
20 + return data;
21 + }
22 +
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 +
9 9   form.on('submit', function (event) {
10 10   event.preventDefault();
11 11  
12 - var data = $.param(form.serializeArray());
41 + var data = getFormData();
42 +
43 + console.log(data)
13 13  
14 14   submitButton.prop('disabled', true);
15 -
46 +/*
16 16   $.post({
17 17   url: serviceURL,
18 18   data: data
... ... @@ -28,13 +28,12 @@
28 28   form[0].reset();
29 29   }).fail(function (xhr) {
30 30   var errorBoxContent = errorBox.find('.box div p');
31 - errorBoxContent.text(xhr.statusText);
62 + errorBoxContent.text(xhr.responseJSON.message);
32 32   errorBox.toggleClass('hidden');
33 33   if (successBox.is(':visible')) {
34 34   successBox.toggleClass('hidden');
35 35   }
36 - }).always(function () {
37 37   submitButton.prop('disabled', false);
38 - });
68 + });*/
39 39   });
40 40  });