title: Send data to a php script with AngularJS
body: <p>I'm new in AngularJS and following some tutorials I was able to create a simple page and a simple form.</p>
  
  <p>The problem is that every time I submit the form seems that the script is sending empty data.</p>
  
  <p>This is my html:</p>
  
  <pre><code>&lt;div class="jumbotron text-center"&gt;
          &lt;h1&gt;Contatti&lt;/h1&gt;
  
          &lt;p ng-show="message"&gt;{{ message }}&lt;/p&gt;
      &lt;/div&gt;
  
  &lt;div class="row"&gt;
      &lt;div class="col-lg-8"&gt;
          &lt;form ng-submit="processForm()"&gt;
              &lt;div class="form-group" ng-class="{ 'has-error' : errorName }"&gt;
                  &lt;label&gt;Nome&lt;/label&gt;
                  &lt;input type="text" name="name" class="form-control" placeholder="chris" ng-model="formData.name"&gt;
                   &lt;span class="help-block" ng-show="errorName"&gt;{{ errorName }}&lt;/span&gt; 
              &lt;/div&gt;
              &lt;button type="submit" class="btn btn-large"&gt;
                  Salva
              &lt;/button&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;pre&gt;
      {{ formData }}
  &lt;/pre&gt;
  </code></pre>
  
  <p>This is the js:</p>
  
  <pre><code>//Creo il modulo e includo ngRoute come dipendenza
  var scotchApp = angular.module('scotchApp', ['ngRoute']);
  
  
  //Configuro le routes
  scotchApp.config(function($routeProvider){
  
      $routeProvider
  
          .when('/', {
              templateUrl: 'pages/home.html',
              controller: 'mainController'
          })
  
          .when('/chi-siamo', {
              templateUrl: 'pages/chi-siamo.html',
              controller: 'aboutController'
          })
  
          .when('/contatti', {
              templateUrl: 'pages/contatti.html',
              controller: 'contactController'
          });
  
  });
  
  //Creo il controller che gestisce la home
  scotchApp.controller('mainController', function($scope){
      $scope.message = "Sono in home";
  });
  
  //Controller che gestisce la pagina chi-siamo
  scotchApp.controller('aboutController', function($scope){
      $scope.message = "Sono in Chi siamo";
  });
  
  
  //Controller che gestisce la pagina contatti
  scotchApp.controller('contactController', function($scope, $http){
  
      $scope.formData = {};
  
      $scope.processForm = function(){
  
  
          console.log($scope.formData);
  
          $http.post('process.php', $scope.formData)
               .success(
                  function(data){
  
                      console.log(data);
  
                      if( data.success )
                      {
                          $scope.message = data.message;
                      }
                      else
                      {
                          $scope.errorName = data.errors.name;
                      }
  
                  }
               );
      }
  });
  </code></pre>
  
  <p>and this is a very simple php script:</p>
  
  <pre><code>&lt;?php
  // process.php
  
  $errors = array();  // array to hold validation errors
  $data = array();        // array to pass back data
  
  
  // validate the variables ========
  if (trim($_POST['name']) == '')
    $errors['name'] = 'Name is required.';
  
  // return a response ==============
  
  // response if there are errors
  if ( count($errors) &gt; 0 ) {
  
    // if there are items in our errors array, return those errors
    $data['success'] = false;
    $data['errors']  = $errors;
  } else {
  
    // if there are no errors, return a message
    $data['success'] = true;
    $data['message'] = 'Success!';
  }
  
  // return all our data to an AJAX call
  echo json_encode($data);
  </code></pre>
  
  <p>Even if I write some data in my input in the console I get:</p>
  
  <pre><code>Object {success: false, errors: Object}
  errors: Object
  name: "Name is required."
  __proto__: Object
  success: false
  __proto__: Object
  </code></pre>
  
  <p>Am I missing something?</p>