Skip to content

Commit f8cdffb

Browse files
committed
Merge pull request #46 from jtyost2/f/feedback
Provide Simple Feedback on the state of the requests
2 parents a7ca731 + 69f926e commit f8cdffb

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

form.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33

44
if (isset($_POST) && !empty($_POST)) {
55
$SubmitForm = new SubmitForm();
6-
$SubmitForm->call($_POST);
6+
if ($SubmitForm->call($_POST)) {
7+
echo true;
8+
} else {
9+
echo false;
10+
}
711
}

index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
<h1>Secret Santa</h1>
3838
<p>Add each person's name and email who is participating in the Secret Santa drawing. Select the suggested price and hit the send email button. Everyone will receive an email with who they have been randomly select to purchase a gift for.</p>
3939
</div>
40+
<div class="feedback">
41+
</div>
4042

4143
<form class="form-horizontal" role="form" data-number-of-people="0" method="POST" action ="./form.php">
4244

js/jquery.scripts.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,37 @@ function newFormElementsString(numberOfPeople) {
2424
return formString;
2525
}
2626

27+
function formFeedback(status) {
28+
if (status == 1) {
29+
$('.feedback').html("<div class='alert alert-success' id='_formFeedback' role='alert'>Every person was randomly assigned a Secret Santa.</div>");
30+
} else {
31+
$('.feedback').html("<div class='alert alert-warning' id='_formFeedback' role='alert'>Something failed and the emails did not go out. Please <a href="/">try again</a>.</div>");
32+
}
33+
34+
}
35+
36+
function formStarted() {
37+
$('.feedback').html("<div class='alert alert-info' id='_formStarted' role='alert'>Randomizing and Sending out the emails</div>");
38+
}
39+
40+
function submitForm(form) {
41+
formStarted();
42+
$.post(
43+
form.attr('action'),
44+
form.serialize(),
45+
function(data, textStatus) {
46+
formFeedback(data);
47+
}
48+
);
49+
}
50+
2751
jQuery(document).ready(function(){
2852
$('button._add_person').on('click', function() {
2953
addAnotherPerson();
3054
});
55+
56+
$('form').on('submit', function(event){
57+
submitForm($(this));
58+
event.preventDefault();
59+
});
3160
});

0 commit comments

Comments
 (0)