Skip to content

Commit

Permalink
Merge pull request #46 from jtyost2/f/feedback
Browse files Browse the repository at this point in the history
Provide Simple Feedback on the state of the requests
  • Loading branch information
justinyost committed Dec 8, 2014
2 parents a7ca731 + 69f926e commit f8cdffb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion form.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@

if (isset($_POST) && !empty($_POST)) {
$SubmitForm = new SubmitForm();
$SubmitForm->call($_POST);
if ($SubmitForm->call($_POST)) {
echo true;
} else {
echo false;
}
}
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
<h1>Secret Santa</h1>
<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>
</div>
<div class="feedback">
</div>

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

Expand Down
29 changes: 29 additions & 0 deletions js/jquery.scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,37 @@ function newFormElementsString(numberOfPeople) {
return formString;
}

function formFeedback(status) {
if (status == 1) {
$('.feedback').html("<div class='alert alert-success' id='_formFeedback' role='alert'>Every person was randomly assigned a Secret Santa.</div>");
} else {
$('.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>");
}

}

function formStarted() {
$('.feedback').html("<div class='alert alert-info' id='_formStarted' role='alert'>Randomizing and Sending out the emails</div>");
}

function submitForm(form) {
formStarted();
$.post(
form.attr('action'),
form.serialize(),
function(data, textStatus) {
formFeedback(data);
}
);
}

jQuery(document).ready(function(){
$('button._add_person').on('click', function() {
addAnotherPerson();
});

$('form').on('submit', function(event){
submitForm($(this));
event.preventDefault();
});
});

0 comments on commit f8cdffb

Please sign in to comment.