-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformSubmit.html
91 lines (74 loc) · 2.67 KB
/
formSubmit.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<!-- The title of the form -->
<title>xAPI Form Example</title>
<!-- JS and CSS Dependencies: -->
<!-- xAPI base functionality -->
<script src="dist/tincan-min.js"></script>
<!-- Setting up the xAPI connection from launch data -->
<script src="dist/xapi-interface.js"></script>
<!-- Functionality for enabling form submission over xAPI -->
<script src="dist/xapi-form-submit.js"></script>
<!-- Base style sheet -->
<link rel="stylesheet" href="style.css" />
</head>
<body>
<!-- Data entry form -->
<form id="dataform" class="padded">
<div class="center">
<div class="small-block">
<label class="input-title" for="top-input">Example Input</label>
<input type="text" name="exampleInput" class="full" />
</div>
</div>
<!-- Line separator -->
<hr />
<!-- Submit button (centred) -->
<div class="center">
<input type="submit" value="Submit" id="submit-button" />
</div>
<!-- Saved status (centred) -->
<div class="center spaced" id="status-message">
<div class="small-block">Form has been submitted.</div>
</div>
</form>
<!-- Initialise functionality -->
<script>
// Find the status box labelled with the id "status"
var statusBox = document.getElementById("status-message");
// Hide this box
statusBox.style.display = "none";
// Find the form element with the id "dataform"
var form = document.getElementById("dataform");
// Find the submit button
var submitButton = document.getElementById("submit-button");
// Function to run when the form is about to be submitted
var onSubmitStart = function (formData) {
// Hide the status box
statusBox.style.display = "none";
// Disable the submit button
submitButton.disabled = true;
};
// Function to run when the form has been submitted
var onSubmitComplete = function (error, formData, response) {
if (error) {
// Submission couldn't complete
// Show error message
alert("Unable to submit form. Try again later.");
console.log(error, formData, response);
} else {
// Submission succeeded
// Show the status box
statusBox.style.display = "";
}
// Re-enable the submit button
submitButton.disabled = false;
};
// Initialise the xAPI functionality and submit the data
// over xAPI when this form is submitted
initXApiForm(form, onSubmitStart, onSubmitComplete);
</script>
</body>
</html>