Guest User

far_app.js

a guest
Apr 23rd, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. angular.module('far_login',[])
  2. .controller('far_formcontrol',['$scope','$http', function($scope, $http) {
  3.     // function to submit the form after all validation has occurred            
  4.     $scope.submitForm = function() {
  5.         console.log('First Name : ' , $scope.fname);
  6.         console.log('Email : ' , $scope.email);
  7.         console.log('Last Name: ', $scope.lname);
  8.         // check to make sure the form is completely valid
  9.         if ($scope.sform.$valid) {
  10.             $http({
  11.                 url: 'http://localhost:8181/far_submit.php',
  12.                 method: 'POST',
  13.                 headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  14.                 transformRequest: function(obj) {
  15.                     var str = [];
  16.                     for(var p in obj)
  17.                     str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
  18.                     return str.join("&");
  19.                 },
  20.                 data: {"name": $scope.fname, "email": $scope.email, "lname": $scope.lname}
  21.             })
  22.             .then(function(response) {
  23.                 console.log(response)
  24.             })
  25.             .catch(function  (error) {
  26.                 console.log(error);
  27.             });
  28.  
  29.         } else {
  30.             alert('our form is not amazing');  
  31.         }
  32.     };
  33. }]);
Add Comment
Please, Sign In to add comment