I want to insert user data into databse but I can’t send from data through
angularjs and i am new to angular. I check by print_r($_POST) in insert.php but it displays as empty array.How can i send form data using php .please help me
HTML
<form name="form" ng-submit="signup()">
<div class="form-group">
<label for="Name">Name</label>
<input type="text" class="form-control" placeholder="Enter your name" name="name" ng-pattern="/^[a-zA-Z]*$/" required ng-model="user.name">
<span ng-show="form.name.$dirty && form.name.$error.required">Enter your name</span>
<span ng-show="form.name.$dirty && form.name.$error.pattern">Name in characters only</span>
</div>
<div class="form-group">
<label for="Mobile">Mobile Number</label>
<input type="text" class="form-control" placeholder="Enter your mobile number" name="mobile" required ng-minlength="10" ng-maxlength="10" ng-model="user.mobile">
<span ng-show="form.mobile.$dirty && form.mobile.$error.required">Enter your mobile number</span>
<span ng-show="form.mobile.$dirty && (form.mobile.$error.minlength || form.mobile.$error.maxlength)">Mobile number should be 10 digits</span>
</div>
<div class="form-group">
<label for="Name">Email</label>
<input type="email" class="form-control" placeholder="Enter your email" name="email" required ng-model="user.email">
<span ng-show="form.email.$dirty && form.email.$error.required">Enter your email</span>
<span ng-show="form.email.$dirty && form.email.$error.email">Enter a valid email</span>
</div>
<div class="form-group">
<label for="pwd">Password</label>
<input type="password" class="form-control" placeholder="Enter password" name="password" required ng-minlength="8" ng-model="user.password">
<span ng-show="form.password.$dirty && form.password.$error.required">Enter your password</span>
<span ng-show="form.password.$dirty && form.password.$error.minlength">Password should be 8 characters</span>
</div>
<button class="btn btn-primary btn-block" name="login" id="login_btn" ng-disabled="form.$invalid">Sign up</button>
</form><br><br>
<p class="text-center" id="new"><span>Already have an account</span></p>
<a href="login.php" class="btn btn-default btn-block">Signin</a>
</div>
</div>
</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1 /jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
JS
var app = angular.module('MyApp', []);
app.controller('MyCtrl', function($scope, $http) {
$scope.signup = function(){
var data = $scope.user;
$http.post("insert.php", data).then(function(resp){
console.log(resp);
});
}
});
Source: AngularJS
from Angular Questions https://angularquestions.com/2017/09/27/send-form-data-using-angulajs-not-working/
via @lzomedia #developer #freelance #web
No comments:
Post a Comment