3

view page:

<div ng-controller="LoginCtrl">
<form name="login_form" ng-submit="submit()" >
    Email: <input type="email" ng-model="login.email" required/><br />
    Password: <input type="password" ng-model="login.pass" required/><br />

    <input type="submit" />
</form>

main.js

function LoginCtrl($scope, $http) {
$scope.login = {};
$scope.submit = function(){

    $http({
        method: 'POST',
        url: '/login',
        data: $scope.login,
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}

    }).
        success(function(response) {
            window.location.href = "/login";
        }).
        error(function(response) {
            $scope.codeStatus = response || "Request failed";
        });
}

LoginController:

if ($request->isPost()) {
            $data = json_decode(file_get_contents("php://input"));}

i need to fetch data from angular form and pass it to zend controller and perform login check and submit form.Could anybody help with step by step explanation?

2
  • To be a valid HTTP POST, don't you need to have a HTML name attached to the JSON submission? In the login controller, add error_log( file_get_contents("php://input") ); Commented Aug 19, 2013 at 7:22
  • This question appears to be off-topic because it is about tutoring Commented Aug 19, 2013 at 8:31

2 Answers 2

4

Change your main.js like this;

function LoginCtrl($scope, $http) {
$scope.login = {email: "", password: ""};
$scope.login = $.param($scope.login);
$scope.submit = function(){

    $http({
        method: 'POST',
        url: '/login',
        data: $scope.login,
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}

    }).
        success(function(response) {
            window.location.href = "/login";
        }).
        error(function(response) {
            $scope.codeStatus = response || "Request failed";
        });
}

In your php file access your email and password like;

$email = $_REQUEST['email'];
$password = $_REQUEST['password'];

and send these credentials to your zend controller. Hope it helps.

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

Comments

0

I found another post that talks about angular not sending data in a manner that php expects. Namely it is doing a json encoding. When I ran into this issue, the REQUEST was empty. Check out the following post:

AngularJs http post does not send 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.