0

My form code is

      <form name="myForm" ng-controller="Ctrl" action="form.php" method="POST">
      Name: <input name="input" ng-model="userName" name="name" required placeholder="Enter Name"><br>
      Email: <input name="email" ng-model="userEmail" name="email" required placeholder="Enter Email"><br>
      <input type="submit" name="submit"><br>
       <tt>userType = {{userName}}</tt><br>
       <tt>userEmail = {{userEmail}}</tt><br>
      </form>

My script is

<script >
    function Ctrl($scope) {
  $scope.userName = '';
  $scope.userEmail = '';
}
</script>

form.php code is

if(isset($_POST['submit']))
    {
        $name=$_POST['name'];
        $email = $_POST['email'];
        echo $name."<br>";
        echo $email."<br>";
    }

how to pass form value to php , any idea

1
  • which form value eaxctly Commented Jan 28, 2014 at 9:10

2 Answers 2

1

I would prefer to keep my model inside an object:

here is a plunker: http://plnkr.co/edit/fC1GikCS0v1tDVTG37vZ?p=preview

controller

function Ctrl($scope, $http) {

  $scope.user = {
    name : '',
    email: ''
  };

  $scope.submit = function(user){    

     $http.post('/form.php', user);

  }
}

html

<form name="myForm" ng-controller="Ctrl" ng-submit="submit(user)">

  Name: <input type="text" ng-model="user.name"><br>
  Email: <input type="email" ng-model="user.email"><br>

  <input type="submit" name="submit"><br>

</form>
Sign up to request clarification or add additional context in comments.

Comments

0

in ur code above u used name tag twice.. thats y in php code it was not picking up the data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.