-
-
Save jmvanderpol/3695771 to your computer and use it in GitHub Desktop.
AngularJS Contact Form Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ContactCtrl($scope, $http) { | |
$scope.success = false; | |
$scope.httpError = false; | |
$scope.send = function() { | |
var job = { job: { klass: 'msg', args: [$scope.msg]}}; | |
$http.post('/contact',job). | |
success(function(data){ | |
$scope.success = true; | |
$scope.msg = {}; | |
}). | |
error(function(data){ | |
$scope.httpError = true; | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
div '.span6.offset1', 'ng-controller': 'ContactCtrl', -> | |
div '.alert.alert-error', 'ng-show': 'httpError', -> | |
button '.close', 'data-dismiss': 'alert', 'x' | |
strong 'Error! ' | |
text 'An Error occured trying to send message, please contact administrator at admin@charlestoncodes.com' | |
div '.alert.alert-success', 'ng-show': 'success', -> | |
button '.close', 'data-dismiss': 'alert', 'x' | |
strong 'Success! ' | |
text 'Thank you for sending your message, we will contact you shortly!' | |
form name: 'contactForm', -> | |
div '.control-group', 'ng-class': "{error: contactForm.name.$invalid}", -> | |
label 'Full Name' | |
input '.span4', type: 'text', name: 'name', 'ng-model': 'msg.name', required: true, placeholder: 'Your Name' | |
span '.help-inline', 'ng-show': 'contactForm.name.$error.required', 'Required' | |
div '.control-group', 'ng-class': "{error: contactForm.email.$invalid}", -> | |
label 'Email' | |
input '.span4', type: 'email', name: 'email', 'ng-model': 'msg.email', required: true, placeholder: 'you@email.com' | |
span '.help-inline', 'ng-show': 'contactForm.email.$error.required', 'Required' | |
span '.help-inline', 'ng-show': 'contactForm.email.$error.email', 'Not a Email' | |
div '.control-group', 'ng-class': '{error: contactForm.message.$invalid}', -> | |
label 'Message' | |
textarea '.span4', rows: 5, name: 'message', 'ng-model': 'msg.body', required: true | |
span '.help-inline', 'ng-show': 'contactForm.message.$error.required', 'Required' | |
button '.btn.btn-primary.btn-large', 'ng-click': "send()", 'ng-disabled': 'contactForm.$invalid', 'Send' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment