-1

Below is Controller:

app.controller("DemoController", function ($scope, $http) {

$scope.Save = function () { 

    var Details = [];
    Details = $scope.UserForm.AllFields;
    $http.post(
            "api/Add.php",
            {'DemoDetails':$scope.Details}
    ).then(function successCallback(response) {
        // Store response data
        alert(response.data);
    }, function errorCallback(response) {
        alert(response.data);
    });
};

});

Below is HTML form:

`<form method="POST">
<input type="text" placeholder="Email" name="username" required="">
<input type="text" placeholder="Password" name="password" required="">
<input type="submit" name="login" ng-click="Save()" value="login"></label> 
</div>
</form>`;

Below is php script:

 `<?php 
 $postdata = file_get_contents("php://input");
 if(isset($postdata) && !empty($postdata)){

 $request  = json_decode($postdata); 

 $username  = $request->username;
 $password  = $request->password;

 }`;

and save to datatabse

1 Answer 1

0

You have to serialize your form like that:

var serializedData = UserForm.serialize();
scope.onSubmit({data: serializedData});

Before to go further, please take a look on that directive, it is a sharp and fancy way to do what you are trying to do by using directive. Retrieve all inputs values from a form AngularJS

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.